Will
Will

Reputation: 989

Javascript Alert Not Displaying

Having trouble getting the javascript alert to display from my code behind.

c# - On Button Click

if (response != "")
{
    ClientScript.RegisterStartupScript(typeof(Page), "AlertPopup", "<script type='text/javascript'>alert('Day already exists, please edit the existing day');</script>");
    return; 
}

This is coming from within an UpdatePanel. I'm not sure if that makes a difference.

EDIT

Changed to this code, but still no luck:

ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "AlertPopup", "<script type='text/javascript'>alert('Day already exists, please edit the existing day');</script>", true);

SOLUTION

It was loading too many script tags, this code fixed the issue:

ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "AlertPopup", "alert('Day already exists, please edit the existing day');", true);

Upvotes: 1

Views: 531

Answers (1)

Brian Mains
Brian Mains

Reputation: 50728

Since it's coming from an UpdatePanel, try using the ScriptManager.RegisterStartupScript static method.

HTH.

Upvotes: 3

Related Questions