Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET Website Programming Problem-Design-Solution
This is the forum to discuss the Wrox book ASP.NET Website Programming: Problem - Design - Solution, Visual Basic .NET Edition by Marco Bellinaso, Kevin Hoffman; ISBN: 9780764543869
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET Website Programming Problem-Design-Solution section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old September 23rd, 2004, 09:52 PM
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.OnInit(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.
//
InitializeComponent();
base.OnInit(e);
}

/// <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.

Regards

Rael


  #2 (permalink)  
Old September 23rd, 2004, 10:03 PM
Registered User
 
Join Date: Sep 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Typo in first post, function should read...

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

I was playing and forgot to set it back.

  #3 (permalink)  
Old September 24th, 2004, 06:30 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Atlanta, Georgia, USA.
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
Default

>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

I change the auto-gen code in this case. It hasn't ever lost my changes. Some people say this change gets undone by VS, but I have never seen that myself.

It's not terribly hard to switch the order of 2 statements on every page. You're going to do a lot more work than that to each new page you write.

This all changes in ASP.NET 2.0. They have an improved model for handling identity and user personalization. The new master page concept also simplies this type of code by eliminating the user controls for things like the header and footer of each page. As I mentioned before, ThePhile in ASP.NET 2.0 could have a lot fewer lines of code, and still have more functionality.

However, this same code will still compile and run correctly under 2.0. It would require a fundamental redesign to get most of the big advantages of 2.0.

Eric


Similar Threads
Thread Thread Starter Forum Replies Last Post
Base Class for Code-Behind Problem groupmatch BOOK: ASP.NET Website Programming Problem-Design-Solution 3 September 8th, 2004 05:06 AM
classes :: base class is inaccessible .... Kaliste C# 3 July 16th, 2004 04:56 AM
base class inheritance krunch97 VB.NET 2002/2003 Basics 6 April 23rd, 2004 11:48 AM
Page_Load override with base page class nebrown1 BOOK: ASP.NET Website Programming Problem-Design-Solution 1 August 31st, 2003 04:45 AM
Help with DBObject base class projectedNexus BOOK: ASP.NET Website Programming Problem-Design-Solution 1 August 12th, 2003 06:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.