Last post Apr 09, 2010 02:02 PM by sandy060583
Apr 09, 2010 01:18 PM|baburk|LINK
Can anybody explain in detail,
Why MasterPage doesn't have Page_PreInit?
Apr 09, 2010 01:52 PM|SGWellens|LINK
MasterPages are never inited/loaded/rendered independently. They are always combined with a child page to produce Html output. So the Pre_Init event occurs in the Child Page portion of the final result.
Apr 09, 2010 02:02 PM|sandy060583|LINK
It is important to note that Master Page is treated like a control in the Content Pages.
So if a Page has a Master Page associated with it, then the controls on the page will not be initialized and would be null in this stage. Only after the Init() event starts, you can access these controls directly from the page class. Why?
The reason being that all controls placed in the Content Page are within a ContentPlaceholder which is a child control of a MasterPage. Now Master Page is merged and treated like a control in the Content Pages. As I mentioned earlier, all events except the
Init() and Unload() are fired from outermost to the innermost control. So PreInit() in the Page is the first event to fire but User Controls or MasterPage (which is itself a Usercontrol) do not have any PreInit event . Therefore in the Page_PreInit() method,
neither the MasterPage nor any user control has been initialized and only the controls inside the Page class are set to their default values. Only after the Page_PreInit() event the Init() events of other controls fire up.
more : http://www.codeasp.net/articles/asp.net/20/aspnet-page-lifecycle