今天碰到一个问题,在MasterPage的OnLoad中加入一个判断,希望在ContentPage的OnLoad之前执行,结果发现MasterPage的Onload在ContentPage的OnLoad后执行,后来把这个判断移动到MasterPage的OnInit中搞定
在一个单独的页面中,执行顺序为
- PreInit
- Init
- InitComplete
- PreLoad
- Load
- LoadComplete
- PreRender
- PreRenderComplete
在页面有MasterPage的时候
- ContentPage.PreInit
- Master.Init
- ContentPage.Init
- ContentPage.InitComplete
- ContentPage.PreLoad
-
ContentPage.Load
-
Master.Load
- ContentPage.LoadComplete
- ContentPage.PreRender
- Master.PreRender
注意上面高亮的部分,除此之外其他的地方一般是先MasterPage后ContentPage,这里恰恰相反
那么控件的加载和页面的几个事件的关系是什么呢?
一般情况下,页面中的控件回先于OnInit执行,亦即
- Master中控件的Init
- ContentPage中控件的Init
- Master.Init
- Content.Init
- Content.Load
- Master.Load
- Master.中用户控件load
- ContentPage页面中的用户控件的 page_load
可以看到控件的Init在Page的Init前执行,所以在Init中我们就可以放心使用页面中的控件了,但是下面的情况不同
如果你的页面中使用WebControl,或者从WebControl继承的控件,WebControl需要使用CreateChildControls()来加载子控件,这个函数会在这个控件的Init后被调用,也就是说在一个WebControl的OnInit中,是没有办法直接使用其中的控件的,不过我们也可以自己用FindControl把控件加载进来,WebControl的其他方法的加载顺序见下表
Event
Description
<!-- Start Content of Table -->
Init |
You can use the OnInit method to trap this event and initialize member variables and other values. |
LoadViewState |
You can trap this event to customize how the control retrieves information from the ASP.NET hidden ViewState field. |
Load |
This event is raised after you create and initialize the control. This is the best place to make the connection to the database or load document content. You can trap the Load event by adding the OnLoad method to the class. |
PreRender |
This event is raised before ASP.NET renders the control. Any changes to the control's state are saved into the hidden ViewState field. |
SaveViewState |
This event is raised before the control state is persisted into the hidden ViewState field. You can trap the event to customize how this information is stored. |
Render |
You can use the Render method to respond to this event and specify the HTML code that represents the component's content. |
Dispose |
This event is useful for cleanup operations. It's raised before the control is torn down and is the best place to free the resources created during the load phase. |
Unload |
This event is raised before the control is torn down. The official documentation says not to use this event to perform cleanup, and to rely on the Dispose event instead. |
<!-- End Content of Table -->
分享到:
相关推荐
能很直观的了解ASP.NET 2.0页面执行顺序
Validators.zip是在Bet1a,Beta2,RC中自带但在Relase中被移到ASP.NET 2.0补丁包中的AJAX兼容性Validators控件库,在新的ASP.NET2.0补丁包安装之前可以先用此库代替。具体用法祥见Scott老大的Blog ...
首先提出需要解决的问题,然后说明实现的过程,最后在ASP.NET2.0中编写具体的软件代码,其中介绍了很多2.0的新特性,如Master,Theme和Skin等,并且大多数章中都涉及到创建三层的系统,包括数据层、业务逻辑层和...
ASP.NET 2.0 Web窗体语法指导 asp.net 页面事件:顺序与回传 ASP.NET应用程序规划与设计 关于asp.net Session丢失问题的总结
1.4 建立ASP.NET 2.0页面的新IDE 16 1.5 小结 17 第2章 Visual Studio 2005 19 2.1 启动页面 19 2.2 文档窗口 20 2.2.1 文档窗口中的视图 20 2.2.2 标记导航器 21 .2.2.3 页面标签 22 2.2.4 代码改变状态的...
3、ASP.NET 2.0 AJAX Futures January CTP,ASPAJAXSourceCode,AjaxControlToolkit(2个支持2.0),AjaxControlToolkit(2个支持3.5),MicrosoftAjaxLibrary,以及各个组件的解释及安装顺序
首先提出需要解决的问题,然后说明实现的过程,最后在ASP.NET2.0中编写具体的软件代码,其中介绍了很多2.0的新特性,如Master,Theme和Skin等,并且大多数章中都涉及到创建三层的系统,包括数据层、业务逻辑层和...
本书全面介绍了ASP.NET各种编程技能和2.0版中的巨大变化,并详细阐述了2.0版中的每个新特性。书中提供了大量的实例,可帮助读者快速掌握如何在.NET平台下开发功能强大的ASP.NET应用程序。本书适合有一些基础的ASP...
课程简介:ASP.NET 2.0 除了编译模型的改进之外,针对页面生命周期也公开了新的事件来支持新功能,例如母版页、个性化以及集成的设备支持等。增强的缓存功能,以及扩展性支持,本课程主要对以上几个方面进行阐述。...
课程简介:ASP.NET 2.0 除了编译模型的改进之外,针对页面生命周期也公开了新的事件来支持新功能,例如母版页、个性化以及集成的设备支持等。增强的缓存功能,以及扩展性支持,本课程主要对以上几个方面进行阐述。...
LearnSite信息技术学习平台 ◆下载与安装建议: Windows2019 (64位) ...IIS添加角色和功能时.NET Framework3.5功能打勾(包含.net2.0) SqlServer安装时选择“混合模式” ◆帮助网站: http://www.openlearnsite.com/
.Net2.0 + Access + Fso 必须做为站点运行,不能放在站点文件夹里运行! 站点设置要求:首页默认顺序为:index.html,index.aspx
第三节母版页和内容页的事件先后顺序(Page_Load Page_Init)在内容页中访问母版页控件对象 嵌套母版页
Validators.zip是在Bet1a,Beta2,RC中自带但在Relase中被移到ASP.NET 2.0补丁包中的AJAX兼容性Validators控件库,在新的ASP.NET2.0补丁包安装之前可以先用此库代替。具体用法祥见Scott老大的Blog ...
asp.net2.0:扩展ImageButton控件定制自己需要的功能 ASP.NET 2.0 正式版中无刷新页面的开发(示例代码的补充) ASP.NET2.0中themes、Skins轻松实现网站换肤! ASP.NET 2.0 中的代码隐藏和编译 ASP.NET 2.0 Language ...
4、运行setup.exe,缺省安装在“c:\anyoffice.net”,安装完成后,通过IIS新建OA站点,OA站点主目录设置为安装目录下“anyoffice.net\webfoot”,站点默认文档设置为index.aspx,更改站点ASP.NET版本为2.0.50727。...
一、基于.net2.0的解决办法 为了使IIS能够支持.net 2.0,在安装的时候必须先安装iis,然后安装.net 2.0,如果先安装了.net,则在装完iis后必须将.net注册上。注册方法是在命令行中输入: C:\WINDOWS\Microsoft.NET\...
3.4 ASP.NET2.0新增控件 45 3.4.1 ImageMap控件 45 3.4.2 FileUpload控件 48 3.5 客户端处理 52 3.5.1 第一种方式示例: 52 3.5.2第二种方式:动态注册javascript指令块 53 3.6验证控件 54 3.6.1验证控件简介 54 ...
里面有详细的说明文档,弄了一个word给大家看,简单在这介绍一下 安装顺序如下: AspNetMVC3Setup.exe AspNetMVC3Setup_CHS.exe AspNetMVC3ToolsUpdateSetup.exe AspNetMVC3ToolsUpdateSetup_CHS.exe
本博客采用ASP.NET2.0 c# + MSSQL2005 + XML + jquery + anthem.net开发,暂时为单用户版本,以下简单介绍... 程序基于类似petshop的标准三层架构,方便维护与扩展(不过暂时只支持MSSQL数据库-_-||) 前台使用...