ASP. NET 2.0 page Lifecycle

Source: Internet
Author: User
URL: http://www.eggheadcafe.com/articles/20051227.asp

I was searching the web for some information on the ASP. NET 2.0 page lifecycle to see what's new and different from ASP. NET 1.1. this chart was created by Leon andrianarivony, and unfortunately the original URL to it is dead. so I'll start by reproducing it here. this is a 384 k jpeg, so you can copy this and print it, and it will look very nice on the wall of your cubie. I 've got ced the render size because of our page formatting constraints, but the image below is "the full banana ":

As can be seen above, there is a whole bunch of new stuff going on in ASP. NET 2.0.

ASP. NET 2.0 provides a much more granular page lifecycle method stack compared to ASP. NET 1.1. The added methods provide a greater level of control to the web developer. with that added level of control comes the responsibility to understand what these methods do and when they are called. these events can be accessed through the Page Object on any ASP. NET page.

The table below shows the list, and whether the method is active at all times, or only on PostBack.

 

Method Active
Constructor Always
Construct Always
Testdevicefilter Always
Addparsedsubobject Always
Determinepostbackmode Always
Onpreinit Always
Loadpersonalizationdata Always
Initializethemes Always
Oninit Always
Applycontrolskin Always
Applypersonalization Always
Oninitcomplete Always
Loadpagestatefrompersistencemedium PostBack
Loadcontrolstate PostBack
Loadviewstate PostBack
Processpostdata1 PostBack
Onpreload Always
Onload Always
Processpostdata2 PostBack
Raisechangedevents PostBack
Raisepostbackevent PostBack
Onloadcomplete Always
Onprerender Always
Onprerendercomplete Always
Savepersonalizationdata Always
Savecontrolstate Always
Saveviewstate Always
Savepagestatetopersistencemedium Always
Render Always
OnUnload Always

If you really want to see how the "rubber meets the road" in ASP. NET 2.0 you can construct for yourself a test page that overrides each of these methods, like so:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page

{

protected override void AddedControl(Control control, int index)

{

Response.Write("AddedControl Fired on " +control.ID+"<br>");

base.AddedControl(control, index);

}

protected override void AddParsedSubObject(object obj)

{

base.AddParsedSubObject(obj);

Response.Write("AddParsedSubObject" + obj.ToString() +"<BR>");

}

public override void ApplyStyleSheetSkin(Page page)

{

base.ApplyStyleSheetSkin(page);

Response.Write("ApplyStyleSheetSkin " + page.ToString() + "<BR>");

}

protected override void Construct()

{

base.Construct();

// No Response Object here yet!

}

protected override void CreateChildControls()

{

base.CreateChildControls();

Response.Write("CreateChildControls<BR>");

}

protected override ControlCollection CreateControlCollection()

{


Response.Write("CreateControlCollection<BR>");

return base.CreateControlCollection();

}

// etc. etc. just type the keyword "override" and select from the list!

protected void Page_Load(object sender, EventArgs e)

{

}

}


The study guide you will have created by making such a test page will be invaluable in learning how the ASP. NET 2.0 page lifecycle works, the order in which the methods are called (and when/if they are called) and whether the response object (for example) is available at that stage of page class's execution.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.