關(guān)于asp.net中頁(yè)面事件加載的先后順序
Page 執(zhí)行中將按照如下順序激活事件:
Page.PreInit
Page.Init
Page.InitComplite
Page.PreLoad
Page.Load
Page.LoadComplete
Page.PreRender
Page.PreRenderComplete
如果頁(yè)面從另一個(gè)頁(yè)面繼承,如BasePage:System.Web.UI.Page,在BasePage中做了一些擴(kuò)展,如權(quán)限檢查,而其他頁(yè)面從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
更進(jìn)一步,如果ContentPage繼承BasePage,那么,各事件的執(zhí)行順序?qū)⒆兂桑?br />
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
瀏覽下來(lái)發(fā)現(xiàn)并不是我現(xiàn)在所學(xué)的asp.net 1.1,估計(jì)應(yīng)該是asp.net 2.0,
不過(guò)也沒(méi)有關(guān)系,這讓我知道了他們有繼承時(shí)加載的順序。
即:先加載繼承頁(yè)的,在加載自己的,如果繼承頁(yè)有繼承則先加載繼承頁(yè)的繼承。
其實(shí)是個(gè)很簡(jiǎn)單的內(nèi)容。順便寫下Page事件(不知道1.1是不是就這些)
事件處理器名稱 | 發(fā)生時(shí)間 |
Page_Init | 在Web窗體的視圖狀態(tài)加載服務(wù)器控件并對(duì)其初始化。 這是web窗體生命周期的第一步 |
Page_Load | 在Page對(duì)象上載入服務(wù)器控件。由于此時(shí)視圖狀態(tài)信息是可以使用的, 因此載這里可以用代碼來(lái)改變空間的設(shè)置或者載頁(yè)面上顯示文本。 |
Page_PreRender | 應(yīng)用程序?qū)⒁尸F(xiàn)Page對(duì)象 |
Page_Unload | 頁(yè)面從內(nèi)存中卸載 |
Page_Error | 發(fā)生未處理的異常 |
Page_AbortTransaction | 事務(wù)處理被終止 |
Page_CommitTransaction | 事務(wù)處理被接受 |
Page_DataBinding | 把頁(yè)面上的服務(wù)器空間和數(shù)據(jù)源綁定載一起 |
Page_Disposed | Page對(duì)象從內(nèi)存中釋放掉。這是Page對(duì)象生命周期中的最后一個(gè)事件 |
posted on 2012-08-12 14:01 ** 閱讀(426) 評(píng)論(0) 編輯 收藏