Event Order

Monday, December 19, 2005

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.


Comments
quanou Wednesday, August 9, 2006
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
quanou Wednesday, August 9, 2006
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 are now closed.
by K. Scott Allen K.Scott Allen
My Pluralsight Courses
The Podcast!