(转)ASP.NET Forums 页面模型分析
ASP.NET 网页由两部分组成:
- 可视元素,包括标记、服务器控件和静态文本。
- 页的编程逻辑,包括事件处理程序和其他代码。
ASP.NET
提供两个用于管理可视元素和代码的模型,即单文件页模型和代码隐藏页模型。具体内容可以参考MSDN(ms-help:
//MS.MSDNQTR.v80.chs/MS.MSDN.v80/MS.VisualStudio.v80.chs/dv_aspnetcon/html/81b13e7a
-b95b-4285-906f-d2dd77411417.htm)。
在ASP.NET Forums的页面中使用了代码隐藏页模型,但是与典型的代码隐藏页模型又稍有区别。
Default.aspx的内容如下:
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
ASP.NET 页框架支持以下指令:
@ Page 定义 ASP.NET 页分析器和编译器使用的特定于页的属性。只能包含在 .aspx 文件中。
@ Control 定义 ASP.NET 页分析器和编译器使用的控件特定属性。只能包含在 .ascx 文件(用户控件)中。
@ Import 将命名空间显式导入页或用户控件中。
@ Register 将别名与命名空间及类名关联起来,从而允许用户控件和自定义服务器控件在被包括到请求的页或用户控件时呈现。
@ Assembly 在编译过程中将程序集链接到当前页,以使程序集的所有类和接口都可用在该页上。
根据指令语法语法我们解读一下default.aspx:
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
继续往下看页面部分,其中主要是MetaBuilders的Master Pages 控件的用法,具体用法可参考venjiang大哥的文章(了解Master Pages库),类似Asp.Net 2.0中的MasterPage
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
其中mp:ContentContainer中的MasterPageFile指定了"母版页
"的位置,mp:Content通过id与"母版页"中的mp:region相对应,最终的效果是在加载Default.aspx的时候先加载母版页,然
后Default.aspx中的mp:Content添加到母版页中对应的mp:region位置,形成最终的效果。
<meta http-equiv="Refresh" content="300" />页面每300秒刷新一次
<Forums:ForumGroupView runat="server" />
表示在此位置上是Forums:ForumGroupView控件,根据页面指令我们得知对应的控件为AspNetForums.Controls.ForumGroupView,
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/ExpandedBlockStart.gif)
![](../../Images/OutliningIndicators/InBlock.gif)
![](../../Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](../../Images/OutliningIndicators/InBlock.gif)
![](../../Images/OutliningIndicators/InBlock.gif)
![](../../Images/OutliningIndicators/InBlock.gif)
![](../../Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](../../Images/OutliningIndicators/InBlock.gif)
![](../../Images/OutliningIndicators/InBlock.gif)
![](../../Images/OutliningIndicators/InBlock.gif)
![](../../Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](../../Images/OutliningIndicators/InBlock.gif)
![](../../Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](../../Images/OutliningIndicators/InBlock.gif)
![](../../Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](../../Images/OutliningIndicators/None.gif)
ForumGroupView继承自SkinnedForumWebControl,并实现抽象方法InitializeSkin,实现了代码分离和换皮肤。继续向下查看ForumGroupView的皮肤文件名View-ForumGroupView.ascx:
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/ExpandedBlockStart.gif)
![](../../Images/OutliningIndicators/InBlock.gif)
![](../../Images/OutliningIndicators/InBlock.gif)
![](../../Images/OutliningIndicators/InBlock.gif)
![](../../Images/OutliningIndicators/InBlock.gif)
![](../../Images/OutliningIndicators/InBlock.gif)
![](../../Images/OutliningIndicators/InBlock.gif)
![](../../Images/OutliningIndicators/InBlock.gif)
![](../../Images/OutliningIndicators/InBlock.gif)
![](../../Images/OutliningIndicators/InBlock.gif)
![](../../Images/OutliningIndicators/InBlock.gif)
![](../../Images/OutliningIndicators/InBlock.gif)
![](../../Images/OutliningIndicators/InBlock.gif)
![](../../Images/OutliningIndicators/InBlock.gif)
![](../../Images/OutliningIndicators/InBlock.gif)
![](../../Images/OutliningIndicators/InBlock.gif)
![](../../Images/OutliningIndicators/InBlock.gif)
![](../../Images/OutliningIndicators/InBlock.gif)
![](../../Images/OutliningIndicators/InBlock.gif)
![](../../Images/OutliningIndicators/InBlock.gif)
![](../../Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
![](../../Images/OutliningIndicators/None.gif)
然后下一个嵌套的过程又开始了。
写此篇文章,大量参考了venjiang,宝玉,ugoer等诸位大哥的文章,在次对他们表示中心的感谢,首次发文章,文笔粗糙,狗尾续貂还请各位不吝指教。