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
 
Old September 4th, 2004, 08:48 AM
Authorized User
 
Join Date: Aug 2004
Location: , , .
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default Base Class for Code-Behind Problem

Here’s a paragraph from the solution of Chapter 3
“OnInit (shown below) is an important method. What we're doing with our override is calling the OnInit method in the base class (System. Web.UI. Page) and then adding our custom page-load event handler (PhilePage_Load) to the Load delegate holder:”
I tried to write the same code but I have a problem. First here’s the code that I wrote:
I wrote a class called Basepage.cs as following
///////////////////////
public class BasePage: System.Web.UI.Page
{
public BasePage()
    {

    }

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

private void BasePage_Load(object sender, System.EventArgs e)
    {
    Trace.Warn("Here a call to 'BasePage_Load' method of the base class");
    }
}
//////////////
Then I created a new Web Form called WebForm1.aspx and because I don’t know how to make this form inherent from BasePage.cs I deleted the WebForm1.aspx.cs (the code behind) and changed the Page Directive to contain this
Codebehind="WebForm1.aspx.cs" and Inherits="test1.WebForm1"
And here’s the WebForm1.aspx.cs (the code-Behind file that I inherent from BasePage)
////////////////////
public class WebForm1 : BasePage
    {
        private void Page_Load(object sender, System.EventArgs e)
        {
            Trace.Warn("Here call to 'page_Load' of the derived class");
        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {

            InitializeComponent();
            base.OnInit(e);
        }
        private void InitializeComponent()
        {
            this.Load += new System.EventHandler(this.Page_Load);
        }
        #endregion
    }
So the problem is that when I trace this page I found that Page_Load method come first and load before BasePage_Load method so why?????????????????
In thePhile It was normal and PhilePage_Load load first and then Page_Load (of the code-behind) so what’s the problem in my code??????????
Thanks
Marenela


 
Old September 6th, 2004, 07:28 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

You need to make the call to base.Load() for that to fire first. Then put your code behind it.

Brian
 
Old September 7th, 2004, 03:42 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Atlanta, Georgia, USA.
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Switch the order of these 2 calls in OnInit:

  base.OnInit(e); // must come first!!!
  InitializeComponent();

Eric
 
Old September 8th, 2004, 05:06 AM
Authorized User
 
Join Date: Aug 2004
Location: , , .
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello,

Thanks for all of you. I looked on the code (before I come here) and I find it out :D. this book gives me a real world experience.
Thanks
Marenela





Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding Page_Load to base class doesn't work Raeldor BOOK: ASP.NET Website Programming Problem-Design-Solution 2 September 24th, 2004 06:30 AM
Calling base class assignment function gstroud Visual C++ 8 September 23rd, 2004 02:33 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
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.