Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

Page lifecycle, specific events question.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gary W. Smith - 28 Aug 2007 17:31 GMT
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
Juan T. Llibre - 28 Aug 2007 18:19 GMT
Check your view of the order of the events with this one :

http://msdn2.microsoft.com/en-us/library/ms178472(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/
======================================
>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
[quoted text clipped - 37 lines]
>
> Gary
Gary W. Smith - 28 Aug 2007 18:28 GMT
On Aug 28, 10:19 am, "Juan T. Llibre" <nomailrepl...@nowhere.com>
wrote:
> Check your view of the order of the events with this one :
>
[quoted text clipped - 4 lines]
> foros de asp.net, en espa?ol :http://asp.net.do/foros/
> ======================================

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
Juan T. Llibre - 28 Aug 2007 19:38 GMT
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 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/
======================================
On Aug 28, 10:19 am, "Juan T. Llibre" <nomailrepl...@nowhere.com>
wrote:
> Check your view of the order of the events with this one :
>
[quoted text clipped - 4 lines]
> foros de asp.net, en español :http://asp.net.do/foros/
> ======================================

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
Gary W. Smith - 28 Aug 2007 20:50 GMT
On Aug 28, 11:38 am, "Juan T. Llibre" <nomailrepl...@nowhere.com>
wrote:
> Hi, Gary.
>
[quoted text clipped - 17 lines]
> 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
bruce barker - 28 Aug 2007 23:50 GMT
there are two cycles. the application request cycle (see httpapplication
class) and the page cycle. the session handler is loaded before the page
cycle is started by page.

application life cycle:

    http://msdn2.microsoft.com/en-us/library/ms178473.aspx

page life cycle:

    http://msdn2.microsoft.com/en-us/library/ms178472.aspx

if you session is missing at oninit, then you have a coding error, or
are recycling sessions.

-- bruce (sqlwork.com)

> On Aug 28, 10:19 am, "Juan T. Llibre" <nomailrepl...@nowhere.com>
> wrote:
[quoted text clipped - 20 lines]
>
> Gary
bruce barker - 28 Aug 2007 20:44 GMT
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

> 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
[quoted text clipped - 37 lines]
>
> Gary

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.