How to Create a PreInit event in ASP.NET v1.1 – level 300
.Net 2.0 has a PreInit event where the theme and master page can be set. When you are rolling your own theme or master page in v1.1, you need a time for the end page to set or override the them and master page. Here is how I created a PreInit event that fires before I wire up the theme and master page:
protected virtual event EventHandler PreInit;
protected new virtual event EventHandler Init;
protected new virtual event EventHandler Load;
protected new virtual event EventHandler PreRender;
protected new virtual event EventHandler Unload;
protected virtual void OnPreInit(EventArgs e) {
if(PreInit != null)
PreInit(this, e);
}
protected new virtual void OnInit(EventArgs e) {
if(Init != null)
Init(this, e);
}
protected new virtual void OnLoad(EventArgs e) {
if(Load != null)
Load(this, e);
}
protected new virtual void OnPreRender(EventArgs e) {
if(PreRender != null)
PreRender(this, e);
}
protected new virtual void OnUnload(EventArgs e) {
if(Unload != null)
Unload(this, e);
}
#endregion
#region Event Handlers
private void Page_Init(object sender, EventArgs e) {
Trace.Write(“EZWeb.Page”, “Begin PreInitialization”);
this.PreInitializePage();
Trace.Write(“EZWeb.Page”, “End PreInitialization”);
Trace.Write(“EZWeb.Page”, “Begin PreInit”);
OnPreInit(e);
Trace.Write(“EZWeb.Page”, “End PreInit”);
this.InitializePage();
Trace.Write(“EZWeb.Page”, “Begin Init”);
OnInit(e);
Trace.Write(“EZWeb.Page”, “End Init”);
}
I shadow the existing events in my base page and then control the raising of those events. In that way, I can do some work, raise PreInit, do some work, and raise Init. I chose this method particularly for the ease of migration to v2.0 next year.
could you post the full source for this? i’ve been trying for hours now to get something like this to work.
Thanks 4 ure best Articles
If this code isn’t enough to show you what he’s doing.. then you probably need to look at other documentation. It’s quite clear and intuitive.