简体   繁体   中英

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. The assignment is to create a web form for users to submit personal information to a website. 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. 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). This Session object will then be added to the Application state data to save it.

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. However, if the if statement is false, an Alertbox WILL appear. 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.

If you really need it, try to double escape it like below:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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