Unable to RegisterStartupScript from an execution other than Page_Load

843 views Asked by At

I use ScriptManager.RegisterStartupScrit from Page_Load and it works perfect.

When I move the same line to the Page_Unload event, it doesn't work; the script is not registered.

Any suggestions??

1

There are 1 answers

3
Rune Grimstad On BEST ANSWER

The Page_Unload event is called after the page is created and the html is outputted. The event is meant to be used to clean up any resources that must be freed by the page.

Why are you calling ScriptManager.RegisterStartupScript here?

EDIT: See here for an overview over the page life cycle of an ASP.Net page. It should help you to determine where to place your code. Most likely the last time you can call ScriptManager.RegisterStartupScript is at the Page_PreRender event.