理解Asp.Net Pages
2007-05-03 04:48 Jun1st 阅读(557) 评论(2) 编辑 收藏 举报1.动态编译
当一个Asp.Net Page被创建时,实际上创建的是一个.net类, 一个System.Web.UI.Page的实例. 页面的所有内容,包括HTML代码和Script代码,都被编译进这个.net类中.
当有一个Request请求这个页面时,Asp.Net Framework检查被请求页面的相应的类是否存在,如果不存在则把页面编译成.net类,并且把编译了的类(assembly)存放到Temporary Asp.Net Files这个目录中.这个文件夹一般位于
:\WINDOWS\Microsoft.NET\Framework\[version]\Temporary ASP.NET Files
当有新的请求到来时,编译过程将不在需要,先前编译好的类直接执行,并把结果返回给浏览器.
2.控件树
Asp.Net Page可以理解为是一个.Net类的源代码, 除此之外,也可以把Asp.Net Page理解为是一个控件包( a bag of controls).因为有点控件本身可能含有控件,因此更确切点一点,可以把Asp.Net Page理解为一个控件树.
例如:
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
20
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
21
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
22
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
23
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
24
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
25
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
26
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
27
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
28
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3.Code-Behind Pages
Asp.Net Framework允许你创建两种类型的Asp.Net Pages, 单文件Pages和双文件Pages.这两种类型到底怎么样就不再赘述.稍微来看一下code-behind是如何工作的.
在Asp.Net 1.1中,Asp.Net Framework会为表现层页面(.aspx)和code-behind文件(.cs)产生两个单独的类,这两个类之间通过继承相关联,其中表现层页面类继承code-behind类.
由于继承是一个单向的关系,因此这种方法很脆弱.所有在表现层页面中声明的控件也必须同样在code-behind文件中声明,而且属性必须也相同.否则,控件触发的事件就可能不会被code-behind文件所捕获而加以处理.
在Asp.Net 2.0中,引入了一种新的机制:Partial Class.它允许把一个类的定义分散到不同的文件中.因此你就不需要在表现层页面和code-behind文件中同时声明,两者中任何的一个声明都可以在另一个中直接使用.
5.处理页面事件
当你请求一个页面时,页面触发事件的顺序如下:
-
PreInit
-
Init
-
InitComplete
-
PreLoad
-
Load
-
LoadComplete
-
PreRender
-
PreRenderComplete
-
SaveStateComplete
-
Unload