简体   繁体   English

为什么这个警告框没有出现?

[英]Why is this alertbox not appearing?

I've got almost got a web project finished for an assignment, but I've hit a stumbling block in the form of an alertbox that refuses to pop up when called.我几乎完成了一个 Web 项目以完成一项任务,但我遇到了一个障碍,即警报框在调用时拒绝弹出。 The assignment is to create a web form for users to submit personal information to a website.任务是创建一个 Web 表单,供用户向网站提交个人信息。 Once they fill in all the textboxes and click a button to register, that will call the function registerMe in the code behind as seen below.一旦他们填写了所有文本框并单击一个按钮进行注册,这将调用后面代码中的函数 registerMe,如下所示。 Once they do that, the idea is that the function will first check to make sure that the user hasn't already registered on the website, then it will stuff all the values from the Textboxes into a Session object (which is using Candidate.curCandidate as a wrapper).一旦他们这样做了,这个想法是该函数将首先检查以确保用户尚未在网站上注册,然后它将文本框中的所有值填充到会话对象中(使用 Candidate.curCandidate作为包装)。 This Session object will then be added to the Application state data to save it.这个 Session 对象然后将被添加到应用程序状态数据中以保存它。

Now, here's the weird thing.现在,奇怪的事情来了。 In the if statement below, if the statement is true, all the values will be saved to the session and then the Application state data as desired, but the Alertbox won't appear.在下面的 if 语句中,如果该语句为真,则所有值都将保存到会话中,然后根据需要保存应用程序状态数据,但不会出现警报框。 However, if the if statement is false, an Alertbox WILL appear.但是,如果 if 语句为假,则会出现警报框。 So, I'm guessing that somehow reading and writing all these values is interfering with the activation of an Alertbox, but I have no idea why.所以,我猜测以某种方式读取和写入所有这些值会干扰警报框的激活,但我不知道为什么。

    protected void registerMe(object sender, EventArgs e)
    {
        String successText;
        if (Candidate.curCandidate.appProperty == false)
        {
            Candidate.curCandidate.ssNumberProperty = socSec.Text;
            Candidate.curCandidate.emailAddressProperty = email.Text;
            Candidate.curCandidate.userIDProperty = userName0.Text;
            Candidate.curCandidate.passwordProperty = password0.Text;
            Candidate.curCandidate.dateOfBirthProperty = dateBirth.Text;
            Candidate.curCandidate.firstNameProperty = fName0.Text;
            Candidate.curCandidate.lastNameProperty = lName0.Text;
            Candidate.curCandidate.streetAddressProperty = strAdd0.Text;
            Candidate.curCandidate.cityProperty = city0.Text;
            Candidate.curCandidate.stateProperty = state0.Text;
            Candidate.curCandidate.positionProperty = jobs0.SelectedIndex;
            Candidate.curCandidate.applicationStatusProperty = appStatus0.Text;
            Candidate.curCandidate.appProperty = true;
            Application[Candidate.curCandidate.ssNumberProperty]=Candidate.curCandidate;

            successText = "Thank you. Candidate Information Added Successfully.\n" +
                "E-Mail Address You Entered will be used to notify you of any\n" +
                "updates for the position you applied for.";
            ClientScript.RegisterStartupScript(this.GetType(), "myalert",
                "alert('" + successText + "');", true);
        }
        else
        {
            successText = "Registration unsuccessful.";
            ClientScript.RegisterStartupScript(this.GetType(), "myalert",
                "alert('" + successText + "');", true);
        }
    }

Try to remove \\n from successText and see if it works.尝试从successText删除\\n并查看它是否有效。

If you really need it, try to double escape it like below:如果你真的需要它,试着像下面这样双重转义它:

successText = "... Successfully.\\\\n"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM