Common Steps in an ASP.NET Page's Life Cycle

 

I’ve been sifting through code written in Whidbey lately, and noticed that there have been a lot of new events added to the page life cycle of an ASP.NET 2.0 webpage, as opposed to the page life cycle of an ASP.NET v1.1 page.  Since Whidbey is still in Beta (and therefore always subject to change), and since I am somewhat apprehensive about learning new functionality that may never get released, I drew up a basic diagram as well as a list of common tasks that occur during the lifecycles of both ASP.NET v1.1 and v2.0 pages, to use as an easy reference. Being the technical simpleton that I am, I chose to keep the diagram and list… uh… simple :).

Below the diagram is the list of common tasks that are performed during a page’s life cycle in ASP.NET 1.1 and 2.0:

1. Start

HTTPRuntime

  • Global.asax is parsed and compiled.

PreInit

  • Check for IsPostback.
  • Create or recreate dynamic controls.
  • Set the Master page dynamically.
  • Set the StyleSheetTheme property.
  • Set the Culture property.
  • Read or set the Profile property values.

2. Page Initialization

Page_Init

  • Read or change Control properties.
  • Setup handlers for events.
  • Load external template files.

LoadViewState()

  • Load application persistent information to controls.
  • Specify how ViewState is stored.
  • Specify how ViewState is mapped to the internal state. 

3. Load

Page_Load

  • If this is the page’s first time being processed, then perform initial databinding.
  • Read and update control properties.

4. Validation

Validate()

  • Validate information assigned to validation controls. 

5. Event Handling

Page_DataBinding()

  •    Bind data sources to controls. 

Page_PreRender

  •    Make final modifications to the page
  •    Change the control tree structure.

SaveViewState()

6. Rendering

Page_Render

  •        Make changes to the HTML of a page.
  •        Write text for controls on a page.

7. Unload

Page_Dispose

  •    Discard objects used in the page, including the Page object.

Page_Unload

  •    Close open files.
  •    Close open database connections.
  •    Finish logging or other request-specific tasks.

 

I thought I'd add a few handy links for ASP.NET 2.0 Page Life Cycle events in case anyone is interested: An ASP.NET 2.0 Life Cycle diagram to put on your wall, and a fairly comprehensive list of ASP.NET 2.0 Page Life Cycle events that get fired during page execution.  

posted on Sunday, August 07, 2005 12:07 AM by shannonf

Comments

# re: Common Steps in an ASP.NET Page's Life Cycle

Hi...shannonf ,
Thanks for sharing ...
Its simply ..Excelent One...
Tuesday, August 22, 2006 8:45 PM by veeruu

# re: Common Steps in an ASP.NET Page's Life Cycle

Hi sannonf,

Thanks for expaning ASP.NET Page's Life Cycle very clearly.

with ur explanation, i'm now able to understand the ASP.NET Page's life cycle very clealy including the events and methods of the life cycle and when to use what

Thursday, September 07, 2006 12:58 AM by ch.purnima

# re: Common Steps in an ASP.NET Page's Life Cycle

Hi Shannon It is simply Superb and Thank you very much
Thursday, December 28, 2006 5:19 AM by Mahesh Babu

# re: Common Steps in an ASP.NET Page's Life Cycle

hello
I have looking for life cycle of asp pages
and this page seems to be best among all I found
Saturday, February 03, 2007 1:22 AM by Reetika

# re: Common Steps in an ASP.NET Page's Life Cycle

This is definitely one of the more clear and concise diagrams explaining the page life cycle.
Wednesday, March 28, 2007 8:53 AM by Robin

# re: Common Steps in an ASP.NET Page's Life Cycle

Great blog, I was working on this for my company and you have done my work for me. Thanks. Exactly what I was looking for.

It's also interesting to note that Init and Unload are unique, in that they fire from inner-most to outer-most control in the control hierarchy. e.g. if I have a control and add a child control, the child control's Init will fire first. Shouldn't matter much if you follow your guidelines, but an interesting note all the same.

--mm
Sunday, June 17, 2007 12:12 PM by Michael

# re: Common Steps in an ASP.NET Page's Life Cycle

hi,
this is a brilliant presentation. this is very help full for beginners
thanks for help
by
varaprasad
Thursday, December 20, 2007 10:43 PM by varaprasad

# re: Common Steps in an ASP.NET Page's Life Cycle

Exactly what i was looking!

Thanks for sharing.
Monday, February 25, 2008 11:30 AM by Carlos Eduardo Appel Klein - DigitalDesk