469,643 Members | 1,634 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,643 developers. It's quick & easy.

Page_Unload... always

Hi.

Debugging one of my pages I noticed that everytime I call the page,
the first event to run is Page_Load and after it the Page_Unload. If I
postback to the page the Page_Unload runs again. Shouldn't the
Page_Unload event runs only when I close the page or submit the page?
I can't understand why the Unload event runs when I load the page !!

Thanks,

Robert Scheer
Nov 17 '05 #1
1 15496
Page_Unload event happens server-side and has nothing to do with closing the
page. Page lifecycle is as follows per request:

1. Instantiate
2. Initialize
3. TrackViewState
4. LoadViewState (postback)
5. Load postback data (postback, IPostBackDatahandler.LoadPostdata)
6. Load
7. Load postback data for dynamical controls added on Page_Load
8. Raise Changed Events (postback,
IPostBackDatahandler.RaisePostDataChanged)
9. Raise postback event (postback, IPostBackEventHandler.RaisePostBackEvent)
10.PreRender
11. SaveViewState
12. Render
13. Unload
14. Dispose

As you can see Unload phase happens as 13th on the list. Important is that
these sequences happen on every request. Those that have (postback) happen
only on postbacks, but Page_Unload happens on every request. Here the Page
performs cleanup.

Reason is that Page class is created on every request to serve requests and
for example inital request and postbacks are actually server by different
class instances. Therefore Page_Unload happens on every request.

--
Teemu Keiski
MCP, Designer/Developer
Mansoft tietotekniikka Oy
http://www.mansoft.fi

AspInsiders Member, www.aspinsiders.com
ASP.NET Forums Moderator, www.asp.net
AspAlliance Columnist, www.aspalliance.com

"Robert Scheer" <rb******@my-deja.com> wrote in message
news:cf**************************@posting.google.c om...
Hi.

Debugging one of my pages I noticed that everytime I call the page,
the first event to run is Page_Load and after it the Page_Unload. If I
postback to the page the Page_Unload runs again. Shouldn't the
Page_Unload event runs only when I close the page or submit the page?
I can't understand why the Unload event runs when I load the page !!

Thanks,

Robert Scheer

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

19 posts views Thread by Heidi Hundåla | last post: by
4 posts views Thread by Larry Morris | last post: by
3 posts views Thread by Andrew Vickers | last post: by
reply views Thread by chefo | last post: by
7 posts views Thread by Cenk | last post: by
2 posts views Thread by Dan Lichiardopol | last post: by
5 posts views Thread by =?Utf-8?B?Um9sYW5kcGlzaA==?= | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.