Wednesday, December 22, 2004

ASP.NET 1.1 Application/Page Lifecycle

It's essential to understand the execution lifecycle of ASP.NET. There's probably been plenty written on this topic but I just want to do a quick exercise to make sure the order is correct. So I created a simple page with a user control, and traced each event inside Global.asax and page's code behind. Here's the result:
  1. Application_Start //Only occurs when application is loaded
  2. Application_Init //Only occurs when application is loaded
  3. Application_BeginRequest
  4. Application_AuthenticateRequest
  5. Session_Start
  6. Page_Control_Init
  7. Page_Init
  8. Page_Control_LoadViewState
  9. Page_ProcessPostData // In Poskback
  10. Page_Load
  11. Page_Control_Load
  12. Page_RaisePostBackEvent // In Postback
  13. Page_SaveViewState
  14. Page_Control_SaveViewState
  15. Page_Control_Render
  16. Page_Render
  17. Page_Control_Unload
  18. Page_Unload
Notice the order of control events and page events. Control's Init, Render, Unload events occur earlier than Page's equivalents, but control's Load and SaveViewState events come later than Page's.