By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,795 Members | 1,250 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,795 IT Pros & Developers. It's quick & easy.

Page_Unload fires twice on Redirect or Transfer?

P: n/a
This seems odd, but it appears that the Page_Unload event is fired twice on a
Response.Redirect or a Server.Transfer.

The output below demonstrates that during the move from the first to the 2nd
page, the event fires twice on the 1st page during Postback. The "var" set
the first time is visible the 2nd time it fires.

Anyone else notice this?
Thanks,
Jeff

<Page_Unload, page 1>
private void Page_Unload(object sender, EventArgs e)
{

Debug.WriteLine("Page_Unload in UnloadTestPage1");
Debug.WriteLine("var in UnloadTestPage1's Page_Unload: " + var);
var = "second (reset on first Page_Unload)";
}
</>

<output>
RESPONSE.REDIRECT
Page_Load in UnloadTestPage1
Button1_Click in UnloadTestPage1...Response.Redirect("UnloadTestPag e2.aspx")
Page_Unload in UnloadTestPage1
var set in UnloadTestPage1's Page_Unload: "first (default)"
Page_Unload in UnloadTestPage1
var set in UnloadTestPage1's Page_Unload: "second (reset on first
Page_Unload)"
Page_Load in UnloadTestPage2
Page_Unload in UnloadTestPage2

SERVER.TRANSFER
Page_Load in UnloadTestPage1
Button1_Click in UnloadTestPage1...Server.Transfer("UnloadTestPage2 .aspx")
Page_Load in UnloadTestPage2
Page_Unload in UnloadTestPage2
Page_Unload in UnloadTestPage1
var set in UnloadTestPage1's Page_Unload: first (default)
Page_Unload in UnloadTestPage1
var set in UnloadTestPage1's Page_Unload: second (reset on first Page_Unload)
Mar 7 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.