Page lifecycle, specific events question.

G

Gary W. Smith

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
 
G

Gary W. Smith

Check your view of the order of the events with this one :

http://msdn2.microsoft.com/en-us/library/ms178472(VS.80).aspx

Juan,

Thanks for the follow up. This is where I derived most of what I have
presented, and based some of my code off of. I remember some years
ago, during the .Net 1.1 days, they had some wonderful diagrams
presenting the flow, but I have been unable to find them. They
presented a good visual flow of the pages, base pages and controls.

I'm still looking to find out where Session comes into scope though.
It seems that it's after I call base.OnInit in my own base page. I'm
just looking to confirm that.

Gary
 
J

Juan T. Llibre

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/library/ms178473(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/library/ms178581(VS.80).aspx





Check your view of the order of the events with this one :

http://msdn2.microsoft.com/en-us/library/ms178472(VS.80).aspx

Juan,

Thanks for the follow up. This is where I derived most of what I have
presented, and based some of my code off of. I remember some years
ago, during the .Net 1.1 days, they had some wonderful diagrams
presenting the flow, but I have been unable to find them. They
presented a good visual flow of the pages, base pages and controls.

I'm still looking to find out where Session comes into scope though.
It seems that it's after I call base.OnInit in my own base page. I'm
just looking to confirm that.

Gary
 
B

bruce barker

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
 
G

Gary W. Smith

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/library/ms178473(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/library/ms178581(VS.80).aspx

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top