views:

484

answers:

1

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
+2  A: 

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
Zhaph - Ben Duguid