Jeffrey Palermo (.com)

Sponsors

The Lounge

News

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
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.


Posted 11-22-2004 7:21 PM by Jeffrey Palermo

[Advertisement]

Comments

Brian wrote re: How to Create a PreInit event in ASP.NET v1.1 - level 300
on 01-12-2005 2:48 PM
could you post the full source for this? i've been trying for hours now to get something like this to work.
ahmad wrote re: How to Create a PreInit event in ASP.NET v1.1 - level 300
on 01-17-2005 6:59 PM
Thanks 4 ure best Articles
Mike wrote re: How to Create a PreInit event in ASP.NET v1.1 - level 300
on 02-16-2005 4:44 AM
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.