Question

My alert does not pop up. When I debug this with a breakpoint, this line is executed

Response.Write("<script>alert('" + " We don't seem to have this user registered. Please try again " + "') ; location.href='Login.aspx'</script>");
Was it helpful?

Solution

The don't needs to be escaped.

This can be done as follows:

Response.Write("<script>alert('" + " We don\\'t seem to have this user registered. Please try again " + "') ; location.href='Login.aspx'</script>");

It should pop up now.

OTHER TIPS

see below code sample to get the alert :

Code Behind :

protected void Page_Load(object sender, EventArgs e)
{
    System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), "abc", "abc();", true);
}

JavaScript :

function abc(message) {
    alert(message + ", I am an alert box!");
}

Have a look at My Answer for more information

You may try this also..

 System.Web.UI.ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Your Message.');", true);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top