Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What is pre-init event in ASP.NET 2.0 page life cycle?

Answer Posted / pavan

PreInit()
In this Page level event, all controls created during
design time are initialized with their default values. For
e.g., if you have a TextBox control with Text property
= “Hello”, it would be set by now. We can create dynamic
controls here.

This event occurs only for the Page class and
UserControls/MasterPages do not have this method to
override.

Sample code where you can override this method and add your
custom code:


protected override void OnPreInit(EventArgs e)

{
//custom code
base.OnPreInit(e);
}
Note that PreInit() is the only event where we can set
themes programmatically.

Special Case with MasterPages

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.

Is This Answer Correct ?    15 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is is post back property in asp net?

967


Explain the procedure to handle the process request using mhpm events fired? : asp.net mvc

958


What is an asp.net validator? And, mention its types.

973


How can we pass info between 2 asp.net pages?

1016


Can I read the hard disk serial # of the client computer using asp.net?

1015


How many types of session in ASP.NET

1041


Can you explain page lifecycle in net?

926


Describe the .net base class library.

989


How to find out what version of asp.net I am using on my machine?

1055


Explain the reason why the javascript validation not run on the asp.net button but run successfully on the html button?

987


What are the new login controls in asp.net 2.0?

931


How do you change the session time-out value?

989


How does cookies work in asp net?

1015


What is the default Orientation property in a Menu control?

997


What are the different methods of session maintenance in asp.net?

961