When we say life cycle in Asp.net Application, there are two logical Life Cycle we need to understand.
So let’s first understand the Asp.net Application life cycle, and then we look at the page life cycle
In this Article you will learn ASP.Net Page Life Cycle, there are many Events occurs while asp.net pages loading.
On browser when any user request a webpage, it goes through sequence of events to finally generate the response that user see on browser , so during this period some events take place one by one
The best way to practice page life cycle in Asp.net , is to create a new page and declare all events on the page, then put break point on each event and run the application, see what happen, in addition if you have some master page and user controls, try to access them and their properties on every event, this exercise will give you the best understanding of each event in page life cycle.
But here are the quick overviews of each event.
protected void Page_PreInit(object sender,EventArgs e ) { }
Experiment Page Life Cycle
Create a new aspx page with a button an label control on it, notice which events are getting fired at when you load the page first time, then click on button to see what changes has happened and order of page events.
public partial class pagelifecycle : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { lbPageEvent.Text = lbPageEvent.Text + " " + " Load"; } protected void Page_PreInit(object sender, EventArgs e) { // Notice: I have set the text to empty at this event, so when you click on submit button on the page, you will realize what all events are getting fired, also try with IsPostBack lbPageEvent.Text = ""; lbPageEvent.Text = "PreInit"; } protected void Page_Init(object sender, EventArgs e) { lbPageEvent.Text = lbPageEvent.Text + " " + "Init"; } protected void Page_InitComplete(object sender, EventArgs e) { lbPageEvent.Text = lbPageEvent.Text + " " + "InitComplete"; } protected override void OnPreLoad(EventArgs e) { lbPageEvent.Text = lbPageEvent.Text + " " + "PreLoad"; } protected void btnSubmit_Click(object sender, EventArgs e) { lbPageEvent.Text = lbPageEvent.Text + " " + "btnSubmit_Click"; } protected void Page_LoadComplete(object sender, EventArgs e) { lbPageEvent.Text = lbPageEvent.Text + " " + "LoadComplete"; } protected override void OnPreRender(EventArgs e) { lbPageEvent.Text = lbPageEvent.Text + " " + "OnPreRender"; } protected override void OnSaveStateComplete(EventArgs e) { lbPageEvent.Text = lbPageEvent.Text + " " + "OnSaveStateComplete"; } protected void Page_UnLoad(object sender, EventArgs e) { lbPageEvent.Text = lbPageEvent.Text + " " + "PageUnLoad"; } }