What is pre-init event in ASP.NET 2.0 page life cycle?
Answer Posted / ashutosh tripathi
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 ? | 66 Yes | 10 No |
Post New Answer View All Answers
I have an excel file with data, i am importing this excel file data into Sqlserver 2005 database. while importing i am getting wrong data(ie, special characters) in one column(description column), upto some limit the data in that column is coming fine,after that data is coming like below. The "Walter" leather storage bench is one of our most popular styles. The top with the tufting and double stitching finish a very impressive piece. The size is perfect in front of beds and the storage adds another functional bonus. Open it up and sneak al���Ƴ�Â��ƴ�Ã��ƶ�Å�� al���Ƴ�Â��ƴ�Ã��ƶ�Å�� Is there anywhy to resolve this? (I am using recordset in coding for developing import process.) please help me soon.
What do you mean by marshalbyref?
How can you implement the postback property of an asp.net control?
What's the use of response.output.write()?
Securitywise What are the Enhancements in 2.0?
What is Cookies Less Session?
What kind of data we can store in viewstate?
What is the appSettings Section in the web.config file?
What does a switch do?
Define cookie.
What are the different types of sessions in asp.net?
I’m having some trouble with cas. How can I diagnose my problem?
What is application state?
What is the full meaning of asp.net?
What is a SESSION and APPLICATION object?