Development With A Dot

Blog on development in general, and specifically on .NET



My Friends

My Links

Permanent Posts

Portuguese Communities

ASP.NET Page Events Lifecycle

When using  master pages, the normal page event lifecycle is a little different. Here is the actual order:

  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
Posted: Mar 08 2009, 12:24 PM by Ricardo Peres | with 22 comment(s) |
Filed under: ,


Dilip said:

I'm sorry but this sounds like an extremely biased submission.  How many times have you have to utilize each and every one of these events?  

The Asp.Net postback functionality gives a lot of functionality out of the box. The average development shop does not have developers who have mastered SOLID principles, read every one of Uncle Bob's books, implemented TDD with mocks and 85% code coverage etc etc.  For most of these shops, web forms IS simpler.  And utilized correctly, (ControlState instead of ViewState etc), it is possible to do RAD development while at the same time building highly scalable apps.

# March 9, 2009 11:45 AM

Ricardo Peres said:

I agree with Dilip: these events actually DO make things simpler, in my opinion! :-)

# March 9, 2009 12:20 PM

CB said:

Absolutely agree with Dilip and Ricardo!

MVC is the next "big" thing from MS. As we all now and see every now and again (every 3 years on average), not every new thing from MS is necessarily better than the old proven things.

As a web developer at any level, you'd never use all of these events. The .net framework gives you the functionality to do as you see fit in different situations.

It's obvious that the author of the "article" is extremely biased, most likely because they haven't got the knowledge or experience to use Web Forms properly.

The grass is not always greener with new technologies..

# March 21, 2009 5:01 AM

Gareth said:

Webforms is a good abstraction, and as already pointed out, those events are *there* but you typically implement only a few of them in normal circumstances.

I like ASP.NET MVC too tho..

# April 2, 2009 1:14 AM

PB said:

Excellent summary of the ASP.Net page life cycle. Helped me a lot, thanks a lot.

# May 21, 2009 11:30 AM said:

Nice article.

# August 29, 2009 9:43 PM

Coder27 said:

Non-digital folks like the print album. ,

# October 22, 2009 8:33 AM

Stinky86 said:

He would be inclined to call de Vries's   mutation theory, figuratively, the quantum theory of biology. ,

# October 23, 2009 7:16 AM

sksoftmind said:

It is really nice, but it will be more nice if you use Indent:)

# November 10, 2009 12:12 PM

Avinash said:

Why does PreInit gets called only for the content page and not for the master page or user controls

# November 17, 2009 8:24 AM

Ricardo Peres said:

# November 17, 2009 12:36 PM

ahsanm.m said:

nice article,Thanks

# March 16, 2010 5:20 AM

fred said:

Thanks for this list, helped find a problem where I had to use OnPreRenderComplete rather than OnPreRender.

# April 5, 2010 6:01 AM

cayla said:

im really sorry but i dont understand this at all i came here looking for what "the prosection rests its case" means and this comes up??? ok fare enought maybe if i get to learn more about it ill know wat to do otherwise i find it useless for this subject...mii sose assingment is due on friday and no one in mii group is doing any of the work...i have to write the whole script bii mii self...its about a trial at court and we hve to act it out...thnx anyways bii :D

                            from cayla :P

# June 16, 2010 3:42 AM

Ali said:

It's greate, But It is better to explain Events...

# December 23, 2010 2:17 AM

Nwebsolution said:

I found it bit confusing

# June 18, 2011 7:57 AM