Explain the page life cycle in ASP.NET 2.0

转载 2007年10月10日 15:35:00

Explain the page life cycle in ASP.NET 2.0

ASP.NET 2.0 Page Life Cycle - The lifetime of an ASP.NET page is filled with events. A series of processing steps takes place during this page life cycle. Following tasks are performed:

* Initialization
* Instantiation of controls
* Restoration & Maintainance of State
* Running Event Handlers
* Rendering of data to the browser

The life cycle may be broken down into Stages and Events. The stages reflect the broad spectrum of tasks performed. The following stages take place

1) Page Request - This is the first stage, before the page life cycle starts. Whenever a page is requested, ASP.NET detects whether the page is to be requested, parsed and compiled or whether the page can be cached from the system.
2) Start - In this stage, properties such as Request and Response are set. Its also determined at this stage whether the request is a new request or old, and thus it sets the IsPostBack property in the Start stage of the page life cycle.
3) Page Initialization - Each control of the page is assigned a unique identification ID. If there are themes, they are applied. Note that during the Page Initialization stage, neither postback data is loaded, nor any viewstate data is retrieved.
4) Load - If current request is a postback, then control values are retrieved from their viewstate.
5) Validation - The validate method of the validation controls is invoked. This sets the IsValid property of the validation control.
6) PostBack Event Handling - Event handlers are invoked, in case the request is a postback.
7) Rendering - Viewstate for the page is saved. Then render method for each control is called. A textwriter writes the output of the rendering stage to the output stream of the page's Response property.
8) Unload - This is the last stage in the page life cycle stages. It is invoked when the page is completely rendered. Page properties like Respone and Request are unloaded.

Note that each stage has its own events within it. These events may be used by developers to handle their code. Listed below are page events that are used more frequently.

PreInit - Checks the IsPostBack property. To create or recreate dynamic controls. To set master pages dynamically. Gets and Sets profile propety values.
Init - Raised after all controls are initialized, and skin properties are set.
InitComplete - This event may be used, when we need to be sure that all initialization tasks are complete.
PreLoad - If processing on a control or a page is required before the Load event.
Load - invokes the OnLoad event on the page. The same is done for each child control on the page. May set properties of controls, create database connections.
Control Events - These are the control specific events, such as button clicks, listbox item selects etc.
LoadComplete - To execute tasks that require that the complete page has been loaded.
PreRender - Some methods are called before the PreRenderEvent takes place, like EnsureChildControls, data bound controls that have a dataSourceId set also call the DataBind method.
Each control of the page has a PreRender event. Developers may use the prerender event to make final changes to the controls before it is rendered to the page.
SaveStateComplete - ViewState is saved before this event occurs. However, if any changes to the viewstate of a control is made, then this is the event to be used. It cannot be used to make changes to other properties of a control.
Render - This is a stage, not an event. The page object invokes this stage on each control of the page. This actually means that the ASP.NET server control's HTML markup is sent to the browser.
Unload - This event occurs for each control. It takes care of cleanup activities like wiping the database connectivities.


COM应用软件开发技术 (bcd的文章)

COM应用软件开发技术    蔡倩 主题词: COM  ActiveX   C++ Builder 1.COM技术概述 COM表示Component Object Model(组件对象模型),它是Mi...
  • ghj1976
  • ghj1976
  • 2001-02-28 14:48:00
  • 1304

老外总结的关于Spring Bean Life Cycle 的文档

老外的blog:http://howtodoinjava.com/ Spring Bean Life Cycle Tutorial Spring bean fact...
  • miqi770
  • miqi770
  • 2016-06-06 16:43:39
  • 668

ASP.NET Page Life Cycle Events

http://www.codeproject.com/Tips/444310/ASP-NET-Page-Life-Cycle-Events A list of events in...
  • SalmonellaVaccine
  • SalmonellaVaccine
  • 2016-06-23 05:06:10
  • 175

The ASP.NET Page Life Cycle

URL:http://www.15seconds.com/issue/020102.htmIntroduction When a page request is sent to the Web ser...
  • coofucoo
  • coofucoo
  • 2007-05-09 09:46:00
  • 1474

Android应用程序的Life Cycle

Android应用程序的Life Cycle 2008-04-06 00:24 一般情况下,每个Android程序运行在各自的linux进程中。当这个应用的某些代码需要执行时,进程就会被创建并且保...
  • myspor
  • myspor
  • 2011-03-30 19:03:00
  • 596

ASP.NET Page Life Cycle

This article describes the ASP.NET Page Life Cycle from the moment the URL is hit from the web brows...
  • skydxd
  • skydxd
  • 2012-10-21 16:20:38
  • 604

ASP.NET 应用程序生命周期(ASP.NET Application Life Cycle)

接触ASP.NET 已经很久了,“所见即所得”的开发方式吸引了很多人,让很多多年从事ASP.NET开发的开发人员对于ASP.NET的认识还停留在“拖控件”的状态。有一句话说得好,优秀的程序员绝对不会说...
  • afandaafandaafanda
  • afandaafandaafanda
  • 2014-12-31 22:09:28
  • 652

软件生存期(life cycle)

软件生存期(1)制定计划(Planning) 确定要开发系统的总目标,给出它的功能、性能、可靠性以及接口等方面的要求;由系统分析员和用户合作,研究完成该软件任务的可行性,探讨解决问题的可能方案,并对可...
  • wyheaven
  • wyheaven
  • 2006-06-06 00:28:00
  • 1831

ASP.NET Page Life Cycle.pptx

  • 2014年11月12日 23:27
  • 1.22MB
  • 下载

Android四大组件之Activity Life Cycle

每创建一个activity就要在清单文件中,添加进去。 创建activity两种方式: ①写一个类继承自activity ②直接new 一个activity 主启动项:          Ac...
  • chen364567628
  • chen364567628
  • 2016-09-28 21:46:50
  • 470
您举报文章:Explain the page life cycle in ASP.NET 2.0