每次都會被頁面導向傳來傳去的順序,和優先次序搞亂
而且我們的網頁又去套用 master page,所以有很多順序又不一樣了

平常只習慣用 Load 和 Button 的 Click 觸發事件,但是有時候又非得要透過這些特殊的順利才會正常
下列這些就很好用了

只是說… 我大概也只有比較常用 Load、PreInit、Init、PreRender  這四種而已
尤其是要讓編輯頁可以順利抓到現在修改的值,就只能用「Init」...

  • 一般情況下:

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

  • 使用了 MasterPage 情況, MasterPage 與 ContentPage 事件順序:

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

參考http://www.dotnetcurry.com/ShowArticle.aspx?ID=61

Explain the Event Life cycle of ASP.NET 2.0?
The events occur in the following sequence. Its best to turn on tracing(<% @Page Trace=”true”%>) and track the flow of events :
PreInit – This event represents the entry point of the page life cycle. If you need to change the Master page or theme programmatically, then this would be the event to do so. Dynamic controls are created in this event.
Init – Each control in the control collection is initialized.
Init Complete* - Page is initialized and the process is completed.
PreLoad* - This event is called before the loading of the page is completed.
Load – This event is raised for the Page and then all child controls. The controls properties and view state can be accessed at this stage. This event indicates that the controls have been fully loaded.
LoadComplete* - This event signals indicates that the page has been loaded in the memory. It also marks the beginning of the rendering stage.
PreRender – If you need to make any final updates to the contents of the controls or the page, then use this event. It first fires for the page and then for all the controls.
PreRenderComplete* - Is called to explicitly state that the PreRender phase is completed.
SaveStateComplete* - In this event, the current state of the control is completely saved to the ViewState.
Unload – This event is typically used for closing files and database connections. At times, it is also used for logging some wrap-up tasks.
The events marked with * have been introduced in ASP.NET 2.0.

參考:
(1) ASP.NET 網頁生命週期概觀
(2) ASP.NET 主版和內容頁面中的事件

創作者介紹
創作者 ⒶⓂⓎ 的頭像
ⒶⓂⓎ

ㄚ咪的幸福收納盒

ⒶⓂⓎ 發表在 痞客邦 留言(0) 人氣()