469,898 Members | 1,605 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

Inherited Page Always Calls Base Page Load Event

WFB
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
Nov 18 '05 #1
1 6554
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" <x@hotmail.com>
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: <eX**************@TK2MSFTNGP10.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: bkftpout.com 12.4.211.11
Path: cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!cpmsftng xa09.phx.gbl!TK2MSFTNGP08.
phx.gbl!TK2MSFTNGP10.phx.gblXref: 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


Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by laredotornado | last post: by
10 posts views Thread by Chad Miller | last post: by
3 posts views Thread by Wayne Brantley | last post: by
4 posts views Thread by asad.naeem | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.