ASP.Net事件循环顺序

时间:2009-05-20 16:15:06

标签: asp.net events event-handling event-loop

我遇到这么多问题(通常在上一页的按钮点击事件之前执行页面加载事件)我决定查找并发布事件循环排序:

     Method                              Called    Controls
     ------------------------------------------------------
1.   Constructor                         Always    All
2.   AddParsedSubObject                  Always    All
3.   DeterminePostBackMode               Always    Page
4.   OnInit                              Always    All
5.   LoadPageStateFromPersistenceMedium  Postback  Page
6.   LoadViewState                       Postback  All
7.   ProcessPostData1                    Postback  Page
8.   OnLoad                              Always    All  //Page Load
9.   ProcessPostData2                    Postback  Page
10.  RaiseChangedEvents                  Postback  Page
11.  RaisePostBackEvent                  Postback  Page //Button Clicks
12.  OnPreRender                         Always    All  //Put page load events here
13.  SaveViewState                       Always    All
14.  SavePageStateToPersistenceMedium    Always    Page
15.  Render                              Always    All
16.  OnUnload                            Always    All

1 个答案:

答案 0 :(得分:5)

以下是您拥有主页时所涉及事件的完整列表:

  

ASP.NET Page Events Lifecycle

  1. Page.OnPreInit
  2. MasterPageControl.OnInit(对于母版页上的每个控件)
  3. Control.OnInit(对于页面上的每个控件)
  4. MasterPage.OnInit
  5. Page.OnInit
  6. Page.OnInitComplete
  7. Page.LoadPageStateFromPersistenceMedium
  8. Page.LoadViewState
  9. MasterPage.LoadViewState
  10. Page.OnPreLoad
  11. Page.OnLoad
  12. MasterPage.OnLoad
  13. MasterPageControl.OnLoad(对于母版页上的每个控件)
  14. Control.OnLoad(对于页面上的每个控件)
  15. OnXXX(控制事件)
  16. MasterPage.OnBubbleEvent
  17. Page.OnBubbleEvent
  18. Page.OnLoadComplete
  19. Page.OnPreRender
  20. MasterPage.OnPreRender
  21. MasterPageControl.OnPreRender(对于母版页上的每个控件)
  22. Control.OnPreRender(对于页面上的每个控件)
  23. Page.OnPreRenderComplete
  24. MasterPageControl.SaveControlState(对于母版页上的每个控件)
  25. Control.SaveControlState(对于页面上的每个控件)
  26. Page.SaveViewState
  27. MasterPage.SaveViewState
  28. Page.SavePageStateToPersistenceMedium
  29. Page.OnSaveStateComplete
  30. MasterPageControl.OnUnload(对于母版页上的每个控件)
  31. Control.OnUnload(对于页面上的每个控件)
  32. MasterPage.OnUnload
  33. Page.OnUnload