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

Page lifecycle, specific events question.

P: n/a
I have a page that inherits from a base page that is currently
overriding all of the On* events. For the most part I'm accomplishing
everything I set out to do with the inheritance, but I wanted to get a
little more information to lock down what I think I know and also to
answer a couple little questions.

Given a base page, and the page inheriting it, as I understand it, the
page lifecycle flows like this:

1) Page is requested
2) Base page OnPreInit is called
3) Base page OnInit is called
4) Main page OnInit is called
5) ViewState is loaded
6) Base page OnPreLoad is called
7) Base page OnLoad is called
8) Main page OnLoad is called
9) Control postback events are processed
10) Base page OnLoadCompleted is called
11) Base page OnPreRender is called
12) Main page OnPreRender is called
13) Base page OnPreRenderComplete is called
14) ViewState is rendered
15) Base page OnUnload is called
16) Main page OnUnload is called.

I have run into some problems with Session though, not being available
during the Base page OnInit until after I have called base.OnInit(e).
My understanding is that Session should always be available, but I
also understand that it can't be available until after the cookies are
available, as the session id is derived from the cookie (and yes, I
know that Session is the root of all evils, but we are working to get
away from them in this app).

So is 1) the above sequence for page lifecycle correct and 2) what is
the session lifecycle on a page (i.e. when does it come in and out of
scope)?

Any help would be greatly appreciated.

Gary

Aug 28 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
the session state is loaded before the page life cycle. the application
object loads state before it calls the page's process request. see the
application object life cycle.

cookies are part of the request and available at BeginRequest, long
before the page cycle (which is in ProcessRequest).

so session state is available in OnPreInit.
-- bruce

Gary W. Smith wrote:
I have a page that inherits from a base page that is currently
overriding all of the On* events. For the most part I'm accomplishing
everything I set out to do with the inheritance, but I wanted to get a
little more information to lock down what I think I know and also to
answer a couple little questions.

Given a base page, and the page inheriting it, as I understand it, the
page lifecycle flows like this:

1) Page is requested
2) Base page OnPreInit is called
3) Base page OnInit is called
4) Main page OnInit is called
5) ViewState is loaded
6) Base page OnPreLoad is called
7) Base page OnLoad is called
8) Main page OnLoad is called
9) Control postback events are processed
10) Base page OnLoadCompleted is called
11) Base page OnPreRender is called
12) Main page OnPreRender is called
13) Base page OnPreRenderComplete is called
14) ViewState is rendered
15) Base page OnUnload is called
16) Main page OnUnload is called.

I have run into some problems with Session though, not being available
during the Base page OnInit until after I have called base.OnInit(e).
My understanding is that Session should always be available, but I
also understand that it can't be available until after the cookies are
available, as the session id is derived from the cookie (and yes, I
know that Session is the root of all evils, but we are working to get
away from them in this app).

So is 1) the above sequence for page lifecycle correct and 2) what is
the session lifecycle on a page (i.e. when does it come in and out of
scope)?

Any help would be greatly appreciated.

Gary
Aug 28 '07 #2

P: n/a
On Aug 28, 11:38 am, "Juan T. Llibre" <nomailrepl...@nowhere.com>
wrote:
Hi, Gary.

re:
!>I'm still looking to find out where Session comes into scope

For that, you need to look at the ASP.NET Application Life Cycle, not at the Page Life Cycle.

http://msdn2.microsoft.com/en-us/lib...73(VS.80).aspx

"When an instance of HttpApplication is created, any configured modules are also created.
For instance, if the application is configured to do so, ASP.NET creates a SessionStateModule module.
After all configured modules are created, the HttpApplication class's Init method is called.

Session comes into scope when the Session_OnStart event occurs.

See :http://msdn2.microsoft.com/en-us/lib...81(VS.80).aspx

Juan T. Llibre, asp.net MVP
asp.net faq :http://asp.net.do/faq/
foros de asp.net, en español :http://asp.net.do/foros/
======================================
Juan,

Thanks for the information. From my reading, the Session scope is
available during the entire page lifetime, which is what I was looking
for. I just didn't know if the Session was avaiable prior to the
cookie collection being available, but it seems that it is.

Thanks,

Gary

Aug 28 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.