View Single Post
Old September 23rd, 2004, 09:52 PM
Raeldor Raeldor is offline
Registered User
Join Date: Sep 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Adding Page_Load to base class doesn't work

The code in the book says the base class should have...

protected override void OnInit(EventArgs e)
    this.Load += new System.EventHandler(this.TestPage_Load);

and that this will get called BEFORE the inherited class page load event. However, auto-generated code in VS2003 shows the following...

override protected void OnInit(EventArgs e)
// CODEGEN: This call is required by the ASP.NET Web Form Designer.

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
    this.Load += new System.EventHandler(this.Page_Load);

This means that the load even for the generated page will ALWAYS get called before our base class load event.

What gives? And what is the best way around this? I assume any chances to auto-gen code will get stamped over, plus it would be a major pain in the a$$ to fix this for every page.