IntroductionJust as in normal life, every ASP.Net control including Page has a life.In our life we go through various events like Birth, Education, Marriage, Job and at the end death. And every event does some important task.Similarly whenever a ASP.Net Page/Control is requested it goes through a sequence of events.Before moving further I would like to put light on some important concepts.How the request is handled by IISWe give an URL to an aspx page in the browser address bar and press enter. What happens next? We get the response in terms of rendered HTML but how?
Request processing by HttpApplicationWhile processing the request, HttpApplication invokes various events which include Module Events, handlers and Page Events.The sequence is:
A developer can extend any of the events as per there convenience and logic.A small Secret about Master Pages and Life Cycle EventsAllthough Master Pages seem like a parent they are actually a child or in short we can say they behave like a user control for pages.<%@ Page Title="My Child Page" Language="C#" MasterPageFile="~/MyMaster.master" AutoEventWireup="true" CodeFile="ChildPage.aspx.cs" Inherits=" ChildPage " %>All events except Init and Unload fires in the manner of from the outside to the inside.That means PageEvent will be fired first and then masterpages then the user controls and so on.PreInit is a kind of event which exists only for Page.Some events get executed only if it's a postback (Full/Asynchronous).Life Cycle EventsPreInitThe properties like IsPostBack have been set at this time.This event will be used when we want to:
Init
LoadViewState
LoadPostDataSome controls like:
PreLoad
Load
Control events
PreRenderRaised after the page object has created all the controls that are required for rendering which includes child controls and composite controls.
SaveViewState
RenderGenerates output (HTML) to be rendered at the client side.
Unload
Reference linkshttp://msdn.microsoft.com/en-us/library/bb470252.aspx http://msdn.microsoft.com/en-us/library/ms178472.aspx http://msdn.microsoft.com/en-us/library/9ysfzy8h(v=vs.71)