RegisterStartupScript with asp:updatepanel

Using Asp.net if you want to add a script to the page from the code behind. The normal Page.RegisterStartupScript will not work if it is called from a button (or any other event) inside an updatePanel.

This is the normal code you would use ( this will work normally if you don’t have an updatePanel)

Page.RegisterStartupScript(“popup”, “<script type=’text/javascript’>alert(‘hello world’);</script>”);

It should be replaced with the following line of code

ScriptManager.RegisterStartupScript(PanelID, PanelID.GetType(), “script key”, “alert(‘hello world’);”, true);

or use it like this same result

ScriptManager.RegisterStartupScript(PanelID, PanelID.GetType(), “script key”, “<script type=’text/javascript’>alert(‘hello world’);</script>”, false);

Hope this was helpful and solved your problem