Page 事件说明及事件执行顺序

Page 事件说明及事件执行顺序

 


  名称 说明
公共事件 AbortTransaction 当用户中止事务时发生。 (继承自 TemplateControl。)
公共事件 CommitTransaction 当事务完成时发生。 (继承自 TemplateControl。)
公共事件 DataBinding 当服务器控件绑定到数据源时发生。 (继承自 Control。)
公共事件 Disposed 当从内存释放服务器控件时发生,这是请求 ASP.NET 页时服务器控件生存期的最后阶段。 (继承自 Control。)
公共事件 Error 当引发未经处理的异常时发生。 (继承自 TemplateControl。)
公共事件 Init 当服务器控件初始化时发生;初始化是控件生存期的第一步。 (继承自 Control。)
公共事件 InitComplete 在页初始化完成时发生。
公共事件 Load 当服务器控件加载到 Page 对象中时发生。 (继承自 Control。)
公共事件 LoadComplete 在页生命周期的加载阶段结束时发生。
公共事件 PreInit 在页初始化开始时发生。
公共事件 PreLoad 在页 Load 事件之前发生。
公共事件 PreRender 在加载 Control 对象之后、呈现之前发生。 (继承自 Control。)
公共事件 PreRenderComplete 在呈现页内容之前发生。
公共事件 SaveStateComplete 在页已完成对页和页上控件的所有视图状态和控件状态信息的保存后发生。
公共事件 Unload 当服务器控件从内存中卸载时发生。 (继承自 Control。)

 

 

ASp.NET 2.0中Page事件的执行顺序

 

Page 执行中将按照如下顺序激活事件:

Page.PreInit
Page.Init
Page.InitComplite
Page.PreLoad
Page.Load
Page.LoadComplete
Page.PreRender
Page.PreRenderComplete

如果页面从令一个页面继承,如BasePage:System.Web.UI.Page,在BasePage中做了一些扩展,如权限检查,而其他页面从BasePage继承,则BasePage和最终Page的事件激活顺序是:

UI.PreInit
Page.PreInit
UI.Init
Page.Init
UI.InitComplite
Page.InitComplite
UI.PreLoad
Page.PreLoad
UI.Load
Page.Load
UI.LoadComplete
Page.LoadComplete
UI.PreRender
Page.PreRender
UI.PreRenderComplete
Page.PreRenderComplete

如果使用了MasterPage,则MasterPage中的事件和ContentPage中的事件按照下面顺序激活:

ContentPage.PreInit
Master.Init
ContentPage.Init
ContentPage.InitComplite
ContentPage.PreLoad
ContentPage.Load
Master.Load
ContentPage.LoadComplete
ContentPage.PreRender
Master.PreRender
ContentPage.PreRenderComplete

更进一步,如果ContentPage继承BasePage,那么,各事件的执行顺序将变成:

UI.PreInit
ContentPage.PreInit
Master.Init
UI.Init
ContentPage.Init
UI.InitComplite
ContentPage.InitComplite
UI.PreLoad
ContentPage.PreLoad
UI.Load
ContentPage.Load
Master.Load
UI.LoadComplete
ContentPage.LoadComplete
UI.PreRender
ContentPage.PreRender
Master.PreRender
UI.PreRenderComplete
ContentPage.PreRenderComplete

 

posted @ 2010-08-24 12:02  超越自我~_~!!  阅读(2292)  评论(0编辑  收藏  举报