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
瀏覽下來發現并不是我現在所學的asp.net 1.1,估計應該是asp.net 2.0,
不過也沒有關系,這讓我知道了他們有繼承時加載的順序。
即:先加載繼承頁的,在加載自己的,如果繼承頁有繼承則先加載繼承頁的繼承。
其實是個很簡單的內容。順便寫下Page事件(不知道1.1是不是就這些)
事件處理器名稱 | 發生時間 |
Page_Init | 在Web窗體的視圖狀態加載服務器控件并對其初始化。 這是web窗體生命周期的第一步 |
Page_Load | 在Page對象上載入服務器控件。由于此時視圖狀態信息是可以使用的, 因此載這里可以用代碼來改變空間的設置或者載頁面上顯示文本。 |
Page_PreRender | 應用程序將要呈現Page對象 |
Page_Unload | 頁面從內存中卸載 |
Page_Error | 發生未處理的異常 |
Page_AbortTransaction | 事務處理被終止 |
Page_CommitTransaction | 事務處理被接受 |
Page_DataBinding | 把頁面上的服務器空間和數據源綁定載一起 |
Page_Disposed | Page對象從內存中釋放掉。這是Page對象生命周期中的最后一個事件 |