This tutorial is brought to you by NetroStar, a
webdesign company.
Each time when a new page in ASP.NET is created it goes through so-called page life cycle, in this tutorial I'll explain you the steps of this life cycle such as initialization or rendering and what's important I'll present you also various events that are raised in different stages. With these events you have the ability to perform some operations in between life cycle stages like for instance initialization of your controls.
In ASP.NET apart from page life cycle there is also an application life cycle. There are some similarities between them however they are different - page life cycle concerns only the given page and application life cycle concerns the whole application. There is also a special file where you can handle events raised by application life cycle called Global.asax. If you want to learn more about ASP.NET application life cycle check out our previous tutorials.
Page Life Cycle
Underneath you can see a list of following steps in page life cycle:
- Page request - first step occurs when user's browser sends a request to the server. ASP.NET checks in the beginning if there exists a cached version of a page that could be send as a response. If there is no such a page in cache the page starts being created and page life cycle commences.
- Start - in fact this is a first stage of page life cycle because page request occurs before it. In this step ASP.NET checks if the request is a postback or if it's a completely new request, also page properties such as Page.Request and Page.Response are initialized. In Page.Request an HttpRequest object is created that contains information concerning current HTTP request and in Page.Response an HttpResponse object is build, within this object you can send response data to client's browser.
- Initialization - during this phase UniqueId property of each control is set, it contains id of a control created automatically by server. Also a master page if it exists is applied to a page.
- Load - in this stage if the processed request is a postback information concerning controls is retrieved from ViewState and ControlState and then it is applied to these controls.
- Postback event handling - now if the request is a postback event handlers from each control are called. Then isValid property of each validator control and of whole page is set by calling Validate method of validator controls.
- Rendering - during this phase whole page is rendered by calling Render method of each of the controls.
- Unload - this stage occurs when the complete and ready page has already been sent to client's browser and is no longer needed. All page properties are deleted and other cleanup operations are conducted.
Take a look at the visual summary of a page life cycle:

Events raised during Page Life Cycle
During page life cycle various events are raised so you can perform necessary operations in various stages of this cycle. In ASP.NET there is a very convenient mechanism called event wire-up, it automatically subscribes to methods named Page_event such as for example Page_Init.
Take a look at the list of the most important events:
- PreInit - this event is raised before initialization begins, here you can for instance set dynamically master page, theme or profile.
- Init - raised when all controls on a page have already been initialized, you can set properties of these controls here.
- InitComplete - raised when whole page has been initialized and ViewState tracking has been turned on, here you can apply changes to the ViewState.
- PreLoad - raised when postback data has been processed, generally in standard use there is no need to perform any operation in here (use other events instead).
- Load - raised when OnLoad method of Page and of all of its controls is called. You can set there properties of these controls.
- Control events - events of specific controls such as for example Button.Click are raised in this stage.
- LoadComplete - raised when all controls have been loaded. You can use it if you need all controls to be already loaded.
- PreRender - raised when Control object has been created. You can use it to make last updates to the content of your page.
- PreRenderComplete - raised just after when DataBind methods of each data-bound controls have been called. You can change data-bound content here.
- SaveStateComplete - raised when ViewState and ControlState for page and for each of the controls have been saved. If you change something in this stage it will not be included in the next postback.
- Render - in this phase Page object call Render method of each control. Please note that this is not an event.
- Unload - this event is raised after all controls has been rendered. You can use it to perform some cleanup operations.
Closing Remarks
In this tutorial you learned about page life cycle in ASP.NET. In the first part you've seen step by step the stages of life cycle and what is happening during that time. Then in the second part I described what events are raised during life cycle and what you can do there. Remember that such a cycle occurs each time when the page is requested.
This tutorial was brought to you by NetroStar, a Miami-based global
seo company.