views:

151

answers:

1

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??

+2  A: 

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.

Rune Grimstad
I want to enter scripts according to what happens during the Button_Click etc. events.
Shimmy
PreRender is after the control events have been handled, so you can probably run your code there
Rune Grimstad
This is the answer.Please update your original answer, and I will mark it.
Shimmy
It's already there. See the last sentence :-)
Rune Grimstad
Oh :)Now I see it...
Shimmy