ScriptManager.RegisterStartupScript code not working - why?
Off the top of my head:
- Use
GetType()
instead oftypeof(Page)
in order to bind the script to your actual page class instead of the base class, - Pass a key constant instead of
Page.UniqueID
, which is not that meaningful since it's supposed to be used by named controls, - End your Javascript statement with a semicolon,
- Register the script during the
PreRender
phase:
protected void Page_PreRender(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, GetType(), "YourUniqueScriptKey",
"alert('This pops up');", true);
}
Try this code...
ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "script", "alert('Hi');", true);
Where UpdatePanel1
is the id
for Updatepanel
on your page