Inherited Page Always Calls Base Page Load Event

Discussion in 'ASP .Net' started by WFB, Dec 30, 2003.

  1. WFB

    WFB Guest

    Hi,

    I have a base class from which all of my pages derive (ABCBasePage). For
    example, ABCCustomerSelect Inherits ABCPasePage. I would now like to have
    ABCPocketSelect which should inherit from ABCCustomerSelect. My problem is
    that when ABCPocketSelect is loaded the Page_Load event in ABCBasePage is
    called, followed by the load event for ABCCustomerSelect - and I would like
    to skip the ABCCustomerSelect load event..

    My basic code is as follows:

    Public Class ABCBasePage : Inherits Page
    Private Sub Page_Load(Sender as Object, e as System.EventArgs) Handles
    MyBase.Load
    'Do code here that should happen on ALL pages
    End Sub
    End Class

    Public Class ABCCustomerSelect : Inherits ABCBasePage
    Private Sub Page_Load(Sender as Object, e as System.EventArgs) Handles
    MyBase.Load
    'Do code here that should happen ABCCustomerSelect only
    End Sub
    End Class

    Public Class ABCPocketSelect : Inherits ABCBasePage
    Private Sub Page_Load(Sender as Object, e as System.EventArgs) Handles
    MyBase.Load
    'Do code here that should happen ABCPocketSelect only
    End Sub
    End Class

    Thanks for any help.

    Joe
     
    WFB, Dec 30, 2003
    #1
    1. Advertising

  2. You'll want to do a couple things...

    First, remove the "Handles MyBase.Load" from your Page_Load method in your
    classes (like ABCCustomerSelect ). The Handles statement automatically
    registers that method for an event, behind the scenes. Also, make
    Page_Load a public method. We'll refer to it later from your child classes.

    Next, add a "Sub New" to these base classes, as this will be your class
    constructor. In this method, you'll want to register your Page_Load event
    by hand. That command is:

    AddHandler Load, Page_Load


    So, now everything should function like it currently does -- the next step
    is to remove the event handler as needed. In your child class
    (ABCPocketSelect) you should put the following lines in its Sub New....
    AddHandler Load, Me.Page_Load ' register its own page_load
    RemoveHandler Load, MyBase.Page_Load ' remove its parent's page_load


    So, check out AddHandler and RemoveHandler in help, it will explain more
    about what's going on there.


    -Charlie

    --------------------------------------------------------------------
    This reply is provided AS IS, without warranty (express or implied).


    --------------------
    >From: "WFB" <>
    >Subject: Inherited Page Always Calls Base Page Load Event
    >Date: Tue, 30 Dec 2003 09:50:02 -0500
    >Lines: 37
    >X-Priority: 3
    >X-MSMail-Priority: Normal
    >X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    >Message-ID: <>
    >Newsgroups: microsoft.public.dotnet.framework.aspnet
    >NNTP-Posting-Host: bkftpout.com 12.4.211.11
    >Path:

    cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.
    phx.gbl!TK2MSFTNGP10.phx.gbl
    >Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet:198847
    >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    >
    >Hi,
    >
    >I have a base class from which all of my pages derive (ABCBasePage). For
    >example, ABCCustomerSelect Inherits ABCPasePage. I would now like to have
    >ABCPocketSelect which should inherit from ABCCustomerSelect. My problem is
    >that when ABCPocketSelect is loaded the Page_Load event in ABCBasePage is
    >called, followed by the load event for ABCCustomerSelect - and I would like
    >to skip the ABCCustomerSelect load event..
    >
    >My basic code is as follows:
    >
    >Public Class ABCBasePage : Inherits Page
    > Private Sub Page_Load(Sender as Object, e as System.EventArgs) Handles
    >MyBase.Load
    > 'Do code here that should happen on ALL pages
    > End Sub
    >End Class
    >
    >Public Class ABCCustomerSelect : Inherits ABCBasePage
    > Private Sub Page_Load(Sender as Object, e as System.EventArgs) Handles
    >MyBase.Load
    > 'Do code here that should happen ABCCustomerSelect only
    > End Sub
    >End Class
    >
    >Public Class ABCPocketSelect : Inherits ABCBasePage
    > Private Sub Page_Load(Sender as Object, e as System.EventArgs) Handles
    >MyBase.Load
    > 'Do code here that should happen ABCPocketSelect only
    > End Sub
    >End Class
    >
    >Thanks for any help.
    >
    >Joe
    >
    >
    >
     
    Charlie Nilsson [MSFT], Dec 30, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff User
    Replies:
    3
    Views:
    865
    Jeff User
    Dec 2, 2005
  2. Matcon
    Replies:
    3
    Views:
    21,723
    Matcon
    May 28, 2008
  3. Phil Johnson
    Replies:
    1
    Views:
    542
    Gregory A. Beamer
    Jul 29, 2009
  4. 7stud --
    Replies:
    11
    Views:
    465
    7stud --
    Nov 9, 2007
  5. Bob
    Replies:
    5
    Views:
    289
Loading...

Share This Page