1

我几乎完成了一个网络项目来完成一项任务,但是我遇到了一个绊脚石,即警报框在被调用时拒绝弹出。任务是创建一个 Web 表单,供用户向网站提交个人信息。一旦他们填写了所有文本框并单击一个按钮进行注册,这将在后面的代码中调用函数 registerMe,如下所示。一旦他们这样做,想法是该函数将首先检查以确保用户尚未在网站上注册,然后它将文本框中的所有值填充到 Session 对象中(使用 Candidate.curCandidate作为包装)。然后这个 Session 对象将被添加到 Application 状态数据中以保存它。

现在,奇怪的事情来了。在下面的 if 语句中,如果该语句为真,所有的值将被保存到 session 中,然后根据需要保存 Application 状态数据,但不会出现 Alertbox。但是,如果 if 语句为假,则会出现一个警报框。所以,我猜想以某种方式读取和写入所有这些值会干扰 Alertbox 的激活,但我不知道为什么。

    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);
        }
    }
4

1 回答 1

2

尝试从中删除\nsuccessText看看它是否有效。

如果您真的需要它,请尝试像下面这样双重转义它:

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

于 2012-11-25T07:48:13.020 回答