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.Reg开发者_JAVA百科isterStartupScript(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);
Since it's coming from an UpdatePanel, try using the ScriptManager.RegisterStartupScript
static method.
HTH.
精彩评论