Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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


  #2 (permalink)  
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
  #3 (permalink)  
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
  #4 (permalink)  
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

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:28 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.