Friday, September 01, 2006 1:53 PM
I am trying to use the Page_Unload event (for the first time) in one of .NET Web Pages. I added the Page_Unload event to my .NET web form (using VS .NET 2003) and set a breakpoint at the first C# instruction of the Page_Unload event and another breakpoint at the first C# instruction of the Page_Load event.
When I run the page in debug mode, the Page_Unload event is being fired when the web form is loaded (right after the Page_Load event is fired). When I exit the web, form the Page_Unload event is never fired.
Does anybody know why???
Friday, September 01, 2006 3:12 PM
You probably have this code snippet in your code-behind:
privatevoid Page_Load(object sender, System.EventArgs e)
// Put user code to initialize the page here
#regionWeb Form Designer generated code
override protected void OnInit(EventArgs e)
private void InitializeComponent()
this.Load += new System.EventHandler(this.Page_Load);
If you remove InitializeComponent(); into OnInit method then Page_Load will not be fired.
Nevertheless, I would to use:
protectedoverride void OnLoad(EventArgs e)
// your code!
Friday, September 01, 2006 5:10 PM
There's seem's to be confusion as to when the Page_Unload event gets fired.
I am expecting the Page_Unload event to be fired when I navigate from my form (that has the Page_Unload event) unto another web form.
Instead, the Page_Unload event is fired at the completion of loading the web form (that has the Page_Unload event).
Is thje Page_Unload fired again when:
1) there was a PostBack in the web form.
2) the user navigates to another web form.
Friday, February 22, 2008 2:31 AM
It's confusing for windows developer. Remember about Unload event defenition. "Occurs when the server control is unloaded from memory" after each load or post back in server side all controls Unloaded from memory. Remember we talking about web application all controls get alived by request and died when response create and send to client.So thats why after load event Unload event called.