search
Twitter Rss Feeds
MicrosoftArticlesForumsGroups
C# .NET
VB.NET
Visual Studio .NET
ADO.NET
Xml/Xslt
VB 6.0
.NET CF
GDI+
LINQ
Deployment
Security
FoxPro
Silverlight / WPF
Entity Framework
RIA Services

Web ProgrammingArticlesForumsGroups
JavaScript
ASP
ASP.NET
Web Services

Non-MicrosoftArticlesForumsGroups
NHibernate
Perl
PHP
Ruby
Java
Linux / Unix
Apple
Open Source

DatabasesArticlesForumsGroups
SQL Server
Access
Oracle
MySQL
Other Databases

OfficeArticlesForumsGroups
Microsoft Excel
Microsoft Word
Microsoft Powerpoint
Publisher
Money

Operating SystemsArticlesForumsGroups
Windows 7
Windows Server
Windows Vista
Windows XP
Windows Update
MAC
Linux / UNIX

Server PlatformsArticlesForumsGroups
Share Point
BizTalk
Site Server
Exhange Server
IIS
Transaction Server

Graphic DesignArticlesForumsGroups
Macromedia Flash
Adobe PhotoShop
Microsoft Expression

OtherArticlesForumsGroups
Subversion / CVS
Ask Dr. Dotnetsky
Active Directory
Networking
Uninstall Virus
Job Openings
Reviews
Search Engines
Resumes

 

ASP.NET 2.0 Page LifeCycle
by Peter A. Bromberg, Ph.D.

Peter Bromberg

I was searching the web for some information on the ASP.NET 2.0 Page LifeCycle to see what's new and different from ASP.NET 1.1. This chart was created by Leon Andrianarivony, and unfortunately the original URL to it is dead. So I'll start by reproducing it here. This is a 384K jpeg, so you can copy this and print it, and it will look very nice on the wall of your cubie. I've reduced the render size because of our page formatting constraints, but the image below is "the full banana":

ASP.NET 2.0 Page Lifecycle Chart

As can be seen above, there is a whole bunch of new stuff going on in ASP.NET 2.0.

ASP.NET 2.0 provides a much more granular page lifecycle method stack compared to ASP.NET 1.1. The added methods provide a greater level of control to the Web developer. With that added level of control comes the responsibility to understand what these methods do and when they are called. These events can be accessed through the Page object on any ASP.NET page.

The table below shows the list, and whether the method is active at all times, or only on PostBack.

 

Method Active
Constructor Always
Construct Always
TestDeviceFilter Always
AddParsedSubObject Always
DeterminePostBackMode Always
OnPreInit Always
LoadPersonalizationData Always
InitializeThemes Always
OnInit Always
ApplyControlSkin Always
ApplyPersonalization Always
OnInitComplete Always
LoadPageStateFromPersistenceMedium PostBack
LoadControlState PostBack
LoadViewState PostBack
ProcessPostData1 PostBack
OnPreLoad Always
OnLoad Always
ProcessPostData2 PostBack
RaiseChangedEvents PostBack
RaisePostBackEvent PostBack
OnLoadComplete Always
OnPreRender Always
OnPreRenderComplete Always
SavePersonalizationData Always
SaveControlState Always
SaveViewState Always
SavePageStateToPersistenceMedium Always
Render Always
OnUnload Always

If you really want to see how the "rubber meets the road" in ASP.NET 2.0 you can construct for yourself a test page that overrides each of these methods, like so:

using System;
       using System.Data;
       using System.Configuration;
       using System.Web;
       using System.Web.Security;
       using System.Web.UI;
       using System.Web.UI.WebControls;
       using System.Web.UI.WebControls.WebParts;
       using System.Web.UI.HtmlControls;
    

public partial class _Default : System.Web.UI.Page
{

protected override void AddedControl(Control control, int index)
{
Response.Write("AddedControl Fired on " +control.ID+"<br>");
base.AddedControl(control, index);
}

protected override void AddParsedSubObject(object obj)
{
base.AddParsedSubObject(obj);
Response.Write("AddParsedSubObject" + obj.ToString() +"<BR>");
}
public override void ApplyStyleSheetSkin(Page page)
{
base.ApplyStyleSheetSkin(page);
Response.Write("ApplyStyleSheetSkin " + page.ToString() + "<BR>");
}
protected override void Construct()
{
base.Construct();
// No Response Object here yet!
}

protected override void CreateChildControls()
{
base.CreateChildControls();
Response.Write("CreateChildControls<BR>");
}

protected override ControlCollection CreateControlCollection()
{

Response.Write("CreateControlCollection<BR>");
return base.CreateControlCollection();
} // etc. etc. just type the keyword "override" and select from the list!

protected void Page_Load(object sender, EventArgs e)
{

}
}

 

The study guide you will have created by making such a test page will be invaluable in learning how the ASP.NET 2.0 Page LifeCycle works, the order in which the methods are called (and when / if they are called) and whether the Response Object (for example) is available at that stage of Page class's execution.


Peter Bromberg is a C# MVP, MCP, and .NET consultant who has worked in the banking and financial industry for 20 years. He has architected and developed web - based corporate distributed application solutions since 1995, and focuses exclusively on the .NET Platform. Pete's samples at GotDotNet.com have been downloaded over 41,000 times. You can read Peter's UnBlog Here.  --><--NOTE: Post QUESTIONS on FORUMS!
Article Discussion:


Pete's Blog   |    Pete's Resume   |    Robbe's Blog   |    Robbe's Resume   |    Archive #2   |    Archive #3   |    Dotnetslackers   |    XmlPitStop   |    Advertise   |   Contact Us   |   Privacy   |   Copyright (c) 2000 - 2009 eggheadcafe.com  All rights reserved.