Event Order

I was going to write a short blog post about event order when a MasterPage is present, but I found MSDN covers the topic well: “Events in ASP.NET Master and Content Pages”. Notice the MasterPage’s Init event will fire before the content page’s Init event, but the content page’s Load event fires before the MasterPage’s Load event.

Sound confusing? Well, the MSDN doc offers advice in a declarative form: “The sequence of events in master and content pages rarely is important for you as page developer”. If you find the order of events is important, you might be tightly coupling your content pages and master pages and sliding towards a type of “Master Page Anti-Pattern” design. Keep the two entities loosely coupled with custom events, and maintainability improves.

Print | posted @ Monday, December 19, 2005 5:15 AM

Comments on this entry:

Gravatar # re: Event Order
by quanou at 8/9/2006 2:20 PM

Hi,
What about the PreInit event for a master page ?
Indeed, I wanted to do this in my master page:
Page.Theme = Profile.MyTheme;
But I got this exception :
"The 'Theme' property can only be set in or before the 'Page_PreInit' event"
But it seems like the Page_PreInit event is not handled for a master page.
Thanks if you could answer
  
Gravatar # re: Event Order
by quanou at 8/9/2006 2:29 PM

Hi Scott,
Well, i just read your other article :)
odetocode.com/.../3091.aspx
Really to bad not being able to change theme for a master page.
  
Comments have been closed on this topic.
Scott Allen
Posts - 869
Comments - 4493
Stories - 14