master頁面,使用者控制項的執行順序,前提是有一個頁面A,引用master頁面B,在兩個頁裡中都分別引用使用者控制項,
使用者控制項A在頁面A中,使用者控制項B在master頁面B中下面我記錄下來他們的執行順序
請注意:
首先執行頁面A的Load事件
接下來運行master頁面B的Load事件
然後運行在master頁面B中使用者控制項B的Load事件
最後運行頁面A中使用者控制項A的Load事件
這是我在調試的時候發現的,希望可以給同樣是ASP.NET開發人員一些協助. 客戶發出POST請求-〉建立Page衍生類別,調用建構函式-〉調用Page類的IHttpHandler.ProcessRequest方法-〉啟用Page類的Init事件-〉調用Page類的CreateChildControls虛方法-〉從POST變數和VIEWSTATE中還原伺服器端控制項狀態-〉啟用Page類的Load事件-〉啟用伺服器端控制項事件-〉啟用Page類的PreRender事件-〉調用Page類的Render虛方法-〉調用Page類的RenderChildren虛方法-〉發送HTTP響應給用戶端-〉啟用Page類的Unload事件-〉丟棄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