divinediu
divinediu

Reputation: 433

Why is my alert not popping up? Asp.net C#

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>");

Upvotes: 0

Views: 2406

Answers (3)

Ajay
Ajay

Reputation: 2080

You may try this also..

 System.Web.UI.ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Your Message.');", true);

Upvotes: 0

SpiderCode
SpiderCode

Reputation: 10122

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

Upvotes: 0

divinediu
divinediu

Reputation: 433

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.

Upvotes: 3

Related Questions