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.


asp.net web api 2.0 实现跨域资源共享

asp.net web api 2 对跨域资源共享的支持1. 同源策略:同源策略是浏览器为保证安全最基本的功能, 只有同源的脚本才能够被执行,那么什么是同源呢?同源是指协议,域名以及端口号都相同,任何...
  • zhanxueguang
  • zhanxueguang
  • 2015年07月09日 20:47
  • 1365

Asp.Net Core 2.0 生成操作数据库文件需要的文件

开发环境 VS2017 + Win7 x64 生成操作数据库文件需要配置或添加的文件 1、Startup.cs public IConfiguration Configuratio...
  • king_hh
  • king_hh
  • 2017年12月29日 16:50
  • 89


花了两天的时间看完了BBC的纪录片《生命》,BBC的纪录片一直是业界标杆,讲一个我的故事吧,在我高一的时候我姐给我看了一个叫做《Wild China》(央视翻译成《美丽中国》,最早的翻译是《野性中...
  • u012247462
  • u012247462
  • 2014年11月26日 19:49
  • 1399


这个问题不是很新了,但是相信对一些新手来说还是有一定难度的,或是一些程序员本身就没有机会接触到这块,正好今天 我配置计算机,把这个过程记录下来,希望以后能用的上,也希望能给大家带来一点帮助(本次试用的...
  • szyone
  • szyone
  • 2013年07月04日 14:38
  • 660

Asp.net Session过期页面处理

效果如下图: 源码如下: 前端: var i = 10; // 获取登录事件,并处理自动跳转 window.onload = func...
  • fanxingthink
  • fanxingthink
  • 2015年11月04日 17:30
  • 809

Asp.net Web Api开发(第四篇)Help Page配置和扩展

为了方面APP开发人员,服务端的接口都应当提供详尽的API说明。但每次有修改,既要维护代码,又要维护文档,一旦开发进度紧张,很容易导致代码与文档不一致。 Web API有一个Help Page插件,可...
  • yeqi3000
  • yeqi3000
  • 2016年09月30日 09:40
  • 2417


主页:http://blog.csdn.net/21aspnet/           时间:2007.3.27 本文讲述如何绘制条形图,折线图,柱形图,面积图等常见图形。 效果图: ...
  • jsjpanxiaoyu
  • jsjpanxiaoyu
  • 2015年03月22日 01:23
  • 1482

【Java多线程】之四:Life Cycle of Thread

Understanding Life Cycle of Thread and Thread States are very important when you are working with Th...
  • chj00128
  • chj00128
  • 2015年08月09日 10:13
  • 342

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

老外的blog:http://howtodoinjava.com/ Spring Bean Life Cycle Tutorial Spring bean fact...
  • miqi770
  • miqi770
  • 2016年06月06日 16:43
  • 589

配置asp.net 2.0的项目到IIS7

首先碰到以下问题: 无法读取配置节"system.web.extensions",因为它缺少节声明 在微软的论坛找到了解决的办法: http://forums.asp.net/p/1...
  • orichisonic
  • orichisonic
  • 2015年11月10日 13:54
  • 593
您举报文章:Explain the page life cycle in ASP.NET 2.0