Home
BBB Yahoo

ASP.NET Page Lifecycle

Events that happen right away

There is an entire life cyle of events that occur when a user requests a page from a browser. Both request and response objects are created.

The IsPostback variable is set to determine if this is the first time the page is rendered or if it is a subsquent request and before the page is posted back.

When a page is requested for the first time or already rendered, we get a postback.

There are a collection of lifecycle events that programmers can program against including:

  • Page_Unload—Page is already processed. Page unload is fired for the page and every control. Do the final cleanup here. Don't make any changes to the page or you will get an exception.
  • Page_PreInit—If the request for this page is a postback, we can check the IsPostback variable. If so the values for any of the controls have not been reconstituted from Viewstate. In this event set things that are global to the page like a master page or theme property. You could create or recreate dynamically created controls here too.
  • Page_Init—Fires after all the controls on the page have been initialized and skins have been applied. Use this event to rewrite specific control properties.
  • Page_InitComplete—Fires after all the initialization is complete. If you have logic that depends on the page and its controls being completely initialized, put it here.
  • Page_PreLoad—Perform any processing on your page or on a control before its load event. Then the preload event for all the controls fire. After this Viewstate and postback data get initialized.
  • Page_Load—Recursively all load events are fired for all the page's controls. Then any specific control event gets fired—like a text changed event.
  • Page_LoadComplete—Controls are all loaded. Viewstate has been reconsituted. Here we can implement any task that required the controls to be loaded and validated.
  • Page_PreRender—Controls are created in memory. Before this gets fired there is each control gets its PreRender event. Use this event to finalize any code before the page is sent to the browser.
  • Page_SaveStateComplete—Before fired, Viewstate has been saved. Any changes that are made will be ignored and not sent to the page. We can execute logic against the page or controls here but won't be sent to the browser.



Copyright © 2010 Robert Stevens. All rights reserved.

This article was commenced on May 7, 2010. Last update: May 7, 2010.


Ad by Google

© 1996-2011 WriteExpress Corporation. All rights reserved.
WriteExpress®, Rhymer® and Unblocking Writers' Block® are registered trademarks of WriteExpress Corporation.