[ASP.NET入门]页面生命周期

简介:
  今天无意之间想起了页面的生命周期,由于很久在数据库和逻辑中旋绕,没有碰到这个咚咚都有点生疏了。为了测了一下就在VS中把几个事件都重写到当前的 ASPX.CS页面中,然后加上断点就可以知道他运行的顺序了。生命周期在表现层当中很有用,特别是如果你要用到多语言,多模板等就一定要掌握每一次请求得周期,至于生命周期的定义就不多说了,也就是从请求到这次请求结束。当你访问一个网站时,你就会对服务端发送一个请求,服务器会响应你的请求被返回你的结果,这就是一个周期了。 

 1 ExpandedBlockStart.gif  protected override  void  Construct()  {
 2InBlock.gif            base.Construct();
 3ExpandedBlockEnd.gif        }

 4 ExpandedBlockStart.gif        protected override  void  FrameworkInitialize()  {
 5InBlock.gif            base.FrameworkInitialize();
 6ExpandedBlockEnd.gif        }

 7 None.gif
 8 ExpandedBlockStart.gif        protected override  void  InitializeCulture()  {
 9InBlock.gif            base.InitializeCulture();
10ExpandedBlockEnd.gif        }

11 None.gif
12 ExpandedBlockStart.gif        protected override  void  AddParsedSubObject(object obj)  {
13InBlock.gif            base.AddParsedSubObject(obj);
14ExpandedBlockEnd.gif        }

15 None.gif
16 ExpandedBlockStart.gif        protected override ControlCollection CreateControlCollection()  {
17InBlock.gif            return base.CreateControlCollection();
18ExpandedBlockEnd.gif        }

19 None.gif
20 ExpandedBlockStart.gif        protected override  void  AddedControl(Control control,  int  index)  {
21InBlock.gif            base.AddedControl(control, index);
22ExpandedBlockEnd.gif        }

23 None.gif
24 ExpandedBlockStart.gif        protected override System.Collections.Specialized.NameValueCollection DeterminePostBackMode()  {
25InBlock.gif            return base.DeterminePostBackMode();
26ExpandedBlockEnd.gif        }

27 None.gif
28 ExpandedBlockStart.gif        protected override  void  OnPreInit(EventArgs e)  {
29InBlock.gif            base.OnPreInit(e);
30ExpandedBlockEnd.gif        }

31 None.gif
32 ExpandedBlockStart.gif        protected override  void  OnInit(EventArgs e)  {
33InBlock.gif            base.OnInit(e);
34ExpandedBlockEnd.gif        }

35 None.gif
36 ExpandedBlockStart.gif        protected override  void  OnInitComplete(EventArgs e)  {
37InBlock.gif            base.OnInitComplete(e);
38ExpandedBlockEnd.gif        }

39 None.gif
40 ExpandedBlockStart.gif        protected override  void  OnPreLoad(EventArgs e)  {
41InBlock.gif            base.OnPreLoad(e);
42ExpandedBlockEnd.gif        }

43 None.gif
44 ExpandedBlockStart.gif        protected override  void  OnLoad(EventArgs e)  {
45InBlock.gif            base.OnLoad(e);
46ExpandedBlockEnd.gif        }

47 None.gif
48 ExpandedBlockStart.gif        protected  void  Page_Load(object sender, EventArgs e)  {
49InBlock.gif            Test.Text = "PageLoad";
50InBlock.gif   
51ExpandedBlockEnd.gif        }

52 None.gif
53 ExpandedBlockStart.gif        protected override  void  OnLoadComplete(EventArgs e)  {
54InBlock.gif            base.OnLoadComplete(e);
55ExpandedBlockEnd.gif        }

56 None.gif
57 ExpandedBlockStart.gif        protected override  void  EnsureChildControls()  {
58InBlock.gif            base.EnsureChildControls();
59ExpandedBlockEnd.gif        }

60 None.gif
61 ExpandedBlockStart.gif        protected override  void  CreateChildControls()  {
62InBlock.gif            base.CreateChildControls();
63ExpandedBlockEnd.gif        }

64 None.gif
65 ExpandedBlockStart.gif        protected override  void  OnPreRender(EventArgs e)  {
66InBlock.gif            base.OnPreRender(e);
67ExpandedBlockEnd.gif        }

68 ExpandedBlockStart.gif        protected override  void  OnPreRenderComplete(EventArgs e)  {
69InBlock.gif            base.OnPreRenderComplete(e);
70ExpandedBlockEnd.gif        }

71 None.gif
72 ExpandedBlockStart.gif        protected override object SaveViewState()  {
73InBlock.gif            return base.SaveViewState();
74ExpandedBlockEnd.gif        }

75 None.gif
76 ExpandedBlockStart.gif        protected override  void  OnSaveStateComplete(EventArgs e)  {
77InBlock.gif            base.OnSaveStateComplete(e);
78ExpandedBlockEnd.gif        }

79 None.gif
80 ExpandedBlockStart.gif        protected override HtmlTextWriter CreateHtmlTextWriter(System.IO.TextWriter tw)  {
81InBlock.gif            return base.CreateHtmlTextWriter(tw);
82ExpandedBlockEnd.gif        }

83 None.gif
84 ExpandedBlockStart.gif        public override  void  RenderControl(HtmlTextWriter writer)  {
85InBlock.gif            base.RenderControl(writer);
86ExpandedBlockEnd.gif        }

87 ExpandedBlockStart.gif        protected override  void  Render(HtmlTextWriter writer)  {
88InBlock.gif            base.Render(writer);
89ExpandedBlockEnd.gif        }

90 ExpandedBlockStart.gif        protected override  void  RenderChildren(HtmlTextWriter writer)  {
91InBlock.gif            base.RenderChildren(writer);
92ExpandedBlockEnd.gif        }

93 None.gif
94 ExpandedBlockStart.gif        protected override  void  OnUnload(EventArgs e)  {
95InBlock.gif            base.OnUnload(e);
96ExpandedBlockEnd.gif        }

   从上面我们可以看出页面执行的顺序,当然还有几个事件没有被列出来,如LoadViewState(发生在OnInit的之后),还有几个特殊的事件我们可以如下做法来扩展程序:
1 None.gif this .Unload  +=   new  System.EventHandler( this .MyPage_Unload);
2 None.gif   this .Load  +=   new  System.EventHandler( this .MyPage_Load);
3 None.gif   this .Init  +=   new  System.EventHandler( this .MyPage_Init);
4 None.gif   this .PreRender  +=   new  System.EventHandler( this .MyPage_PreRender);
  
   本文转自网魂小兵博客园博客,原文链接:http://www.cnblogs.com/xdotnet/archive/2007/05/22/aspnet_pagelife.html,如需转载请自行联系原作者
相关文章
|
3月前
|
开发框架 前端开发 .NET
七天.NET 8操作SQLite入门到实战 - (1)第七天BootstrapBlazor UI组件库引入
七天.NET 8操作SQLite入门到实战 - (1)第七天BootstrapBlazor UI组件库引入
|
22天前
|
开发框架 .NET 物联网
.NET从入门到精通,零基础也能搞定的基础知识教程
.NET从入门到精通,零基础也能搞定的基础知识教程
19 0
|
2月前
|
开发框架 .NET 程序员
C#/.NET该如何自学入门?
C#/.NET该如何自学入门?
|
4月前
|
XML API 数据库
七天.NET 8操作SQLite入门到实战 - 第六天后端班级管理相关接口完善和Swagger自定义配置
七天.NET 8操作SQLite入门到实战 - 第六天后端班级管理相关接口完善和Swagger自定义配置
|
4月前
|
存储 开发框架 .NET
Asp.Net第一章入门之后台处理程序
Asp.Net第一章入门之后台处理程序
30 0
|
8天前
|
安全 数据库 数据安全/隐私保护
七天.NET 8操作SQLite入门到实战 - 第五天引入SQLite-net ORM并封装常用方法
七天.NET 8操作SQLite入门到实战 - 第五天引入SQLite-net ORM并封装常用方法
|
8天前
|
开发框架 .NET API
七天.NET 8操作SQLite入门到实战 - 第四天EasySQLite前后端项目框架搭建
七天.NET 8操作SQLite入门到实战 - 第四天EasySQLite前后端项目框架搭建
|
8天前
|
存储 SQL 关系型数据库
七天.NET 8操作SQLite入门到实战 - 第三天SQLite快速入门
七天.NET 8操作SQLite入门到实战 - 第三天SQLite快速入门
|
4月前
|
SQL Shell 数据库
七天.NET 8操作SQLite入门到实战 - 第二天 在 Windows 上配置 SQLite环境
七天.NET 8操作SQLite入门到实战 - 第二天 在 Windows 上配置 SQLite环境