Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Inherited Page Always Calls Base Page Load Event

Reply
Thread Tools

Inherited Page Always Calls Base Page Load Event

 
 
WFB
Guest
Posts: n/a
 
      12-30-2003
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


 
Reply With Quote
 
 
 
 
Charlie Nilsson [MSFT]
Guest
Posts: n/a
 
      12-30-2003
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!cpmsftng xa09.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
>
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
AutoEventWireup, inherited pages - page base class Phil Johnson ASP .Net 1 07-29-2009 03:18 PM
Run Javascript function upon Page Load from Page Load event handle Matcon ASP .Net 3 05-28-2008 05:15 PM
'Class.inherited' v. 'inherited' syntax inside Class 7stud -- Ruby 11 11-09-2007 06:45 PM
This function has an onClick event that calls a function that calls This function Bob Javascript 5 10-24-2006 04:11 PM
Access inherited aspx control from base aspx ? Jeff User ASP .Net 3 12-02-2005 04:58 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57