ASP.Net 事件循环顺序

发布于 2024-07-22 14:43:54 字数 1151 浏览 6 评论 0原文

我遇到了很多问题(通常是在上一页的按钮单击事件之前执行页面加载事件),因此我决定查找它并发布事件循环顺序:

     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

I've had so many problems with this (usually with page load events being executed before button click events from the previous page) that I decided to look it up and post the event loop ordering:

     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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩心不撩汉 2024-07-29 14:43:54

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

ASP.NET 页面事件生命周期

  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

Here's a complete list of the events that are involved when you have masterpages as well:

ASP.NET Page Events Lifecycle

  1. Page.OnPreInit
  2. MasterPageControl.OnInit (for each control on the master page)
  3. Control.OnInit (for each contol on the page)
  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 (for each control on the master page)
  14. Control.OnLoad (for each control on the page)
  15. OnXXX (control event)
  16. MasterPage.OnBubbleEvent
  17. Page.OnBubbleEvent
  18. Page.OnLoadComplete
  19. Page.OnPreRender
  20. MasterPage.OnPreRender
  21. MasterPageControl.OnPreRender (for each control on the master page)
  22. Control.OnPreRender (for each control on the page)
  23. Page.OnPreRenderComplete
  24. MasterPageControl.SaveControlState (for each control on the master page)
  25. Control.SaveControlState (for each control on the page)
  26. Page.SaveViewState
  27. MasterPage.SaveViewState
  28. Page.SavePageStateToPersistenceMedium
  29. Page.OnSaveStateComplete
  30. MasterPageControl.OnUnload (for each control on the master page)
  31. Control.OnUnload (for each control on the page)
  32. MasterPage.OnUnload
  33. Page.OnUnload
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文