views:

86

answers:

1

Hi

http://www.allinterview.com/showanswers/73327.html


a) If I understand the above article correctly, then when a page has a master page associated with it, then all controls ( those declared in master page and those declared in content page ) created during design time are assigned declarative values only during an Init event?

b) Assuming our page is associated with Master page and also uses a theme --> skin files are also applied during an Init event, so I assume that during an Init event Asp.Net first initializes controls to their declarative values and only then applies skin rules to them?

c) But if a page doesn’t use a master page, then the controls it declares during design time are assigned values prior to Init event?


thanx

+1  A: 

Here's a better article about this on MSDN. Scroll down to Life-cycle Events.

If I'm understanding your questions correctly, all you are asking in a, b, and c happen during Pre_Init. Init event fires after all controls are initialized during Pre_Init. So, during Init you can now read or initialize those controls' properties.

Note that you are still "initializing" control's property during Init.

Example...

<asp:Label ID="Label1" runat="server" CssClass="someclass"></asp:Label>

Init:
Label1.CssClass = "someotherclass";

Correct me if I'm wrong guys...

I believe Label1 is initialzed with CssClass set to "someclass" during Pre_Init and then Label1's CssClass is re-initiazed (initial value is changed) to "someotherclass". So when page is loaded class value will be "someotherclass".

And trying to get access to Label1.CssClass within Pre_Init block won't work since Label1 is not yet done initializing. You have access to control properties from Init.

This initialization order does not change whether you have MasterPage or not. Consider MasterPage as just another control. I believe all controls inside of MasterPage are also initialized during Pre_Init.

Hope this is clear.

Brian Kim
"This initialization order does not change whether you have MasterPage or not. Consider MasterPage as just another control. "But if I’m not mistaken the controls need first to be put into the control tree before they can be assigned their declarative values? And when page has a master page associated with it, then aren’t page’s controls put into the control tree only during the Pre_Init or perhaps even during the Init event? Then if that is the case, then isn’t the earliest that these controls can be assigned their declarative values during Init event?
carewithl