473,371 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,371 software developers and data experts.

Page_load not called in base class

Hi all,

I have a site with the following architecture:

Common.Web.dll - Contains a CommonPageBase class which inherits
System.Web.UI.Page
myadd.dll - Contains PageBase which inherits CommonPageBase
- Contains myPage which inherits PageBase

Each of these classes overrides OnInit and ties an event handler
(Page_load) to the Load event.

The problem is that the Page_Load event is NOT being called in the
PageBase class, although it is in in myPage and CommonPageBase. I can
even step through the code that assigns the event handerl in
PageBase... but the Page_Load is still never called (all Page_Loads are
private).

Any ideas?

Thanks
Andy

Nov 19 '05 #1
5 3130
Reflection is used to find Page_Load, and the derived class' Page_Load is
hiding the base class'. I'd suggest having the base class override OnLoad.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi all,

I have a site with the following architecture:

Common.Web.dll - Contains a CommonPageBase class which inherits
System.Web.UI.Page
myadd.dll - Contains PageBase which inherits CommonPageBase
- Contains myPage which inherits PageBase
Each of these classes overrides OnInit and ties an event handler
(Page_load) to the Load event.

The problem is that the Page_Load event is NOT being called in the
PageBase class, although it is in in myPage and CommonPageBase. I can
even step through the code that assigns the event handerl in
PageBase... but the Page_Load is still never called (all Page_Loads
are private).

Any ideas?

Thanks
Andy

Nov 19 '05 #2
another option is to call the base calss's Page_Load from the derived
class's Page_Load method.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
I'd rather be a hammer than a nail.

"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:b8**************************@msnews.microsoft .com...
Reflection is used to find Page_Load, and the derived class' Page_Load is
hiding the base class'. I'd suggest having the base class override OnLoad.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi all,

I have a site with the following architecture:

Common.Web.dll - Contains a CommonPageBase class which inherits
System.Web.UI.Page
myadd.dll - Contains PageBase which inherits CommonPageBase
- Contains myPage which inherits PageBase
Each of these classes overrides OnInit and ties an event handler
(Page_load) to the Load event.

The problem is that the Page_Load event is NOT being called in the
PageBase class, although it is in in myPage and CommonPageBase. I can
even step through the code that assigns the event handerl in
PageBase... but the Page_Load is still never called (all Page_Loads
are private).

Any ideas?

Thanks
Andy


Nov 19 '05 #3
On Fri, 23 Sep 2005 14:31:52 -0700, Brock Allen wrote:
Reflection is used to find Page_Load, and the derived class' Page_Load is
hiding the base class'. I'd suggest having the base class override OnLoad.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi all,

I have a site with the following architecture:

Common.Web.dll - Contains a CommonPageBase class which inherits
System.Web.UI.Page
myadd.dll - Contains PageBase which inherits CommonPageBase
- Contains myPage which inherits PageBase
Each of these classes overrides OnInit and ties an event handler
(Page_load) to the Load event.

The problem is that the Page_Load event is NOT being called in the
PageBase class, although it is in in myPage and CommonPageBase. I can
even step through the code that assigns the event handerl in
PageBase... but the Page_Load is still never called (all Page_Loads
are private).

Any ideas?

Thanks
Andy

Brock, could you explain this further?
Who is using Reflection?
Which derived class is hiding the base class

I really appreciate your explanation

Thanks

Nov 19 '05 #4
> Brock, could you explain this further?
Who is using Reflection?
Which derived class is hiding the base class

I really appreciate your explanation
I'm going to assume, for the purpose of this discussion, that you're working
with VB.Net, and use VB.Net terminology.

You have created a base page class called "CommonPageBase" and wired up an
event handler ("Page_Load") to the "Load" event of the class, which inherits
from System.Web.UI.Page. Notice that System.Web.UI.Page does not define an
event handler for this event.

Next, you created a class called "Page_Base" which inherits "CommonPageBase"
and wired up an event handler called "Page_Load" to the "Load" event of the
class. Note that the base class already has a method called (named)
"Page_Load." Now, there are several ways of handling an inherited class
having a method defined with the same name as the name of a method in the
base class.

First, unless there is a difference in what the inherited class and what the
base class do in this method, there is no need to re-define it in the
inherited class; it inherits it. Any method in a base class that is defined
as Overrideable, Overrides, or MustOverride is available to (and, in fact,
already exists in) all derived classes of that class. Any method defined as
NotOverridable is not able to be overridden by derived classes. But it can
be re-defined. I'll get back to that shortly.

Overrideable indicates that a derived class may override (re-define) that
member.
Overrides indicates that the member overrides (re-defines) a member in a
base class that the base class inherits, and can therefore be overridden in
a derived class.
MustOverride indicates that an inherited class MUST re-define the member in
the base class.
NotOverridable indicates that an inherited class may NOT override the member
in the base class.

Now, when you create a method in an inherited class with the same name as a
method in the base class, this presents a problem to the compiler. The base
class has defined this method, and the derived class has defined a method
with the same name. So, how should the method (in this case) be executed
when called by name? There are several possibilities:

1. The base class can execute its definition of the method, and the derived
class can execute its definition of the method. Of course, the question then
becomes, which one executes first?
2. The derived class can execute its definition of the method, and the base
class can not.
3. The base class can execute its definition of the method, and the derived
class can not (not really possible).
4. The derived class can execute its definition of the method, and in doing
so, at a point of its own choosing, call the base class's implementation of
the same method.

Now, this dilemma is where the access modifiers (Overridable, MustOverride,
etc) come into play. These define the rules for deciding which of these
scenarios is selected.

If the method is overridable, the inherited class can define its
implementation of the method as "Overrides". This means that the base
class's implementation of the method will NOT be executed, unless the
derived class calls it directly (as in "MyBase.Page_Load()"). Note that the
derived class can call this base class method at any time, or not at all. In
fact, it can call the base class's implementation of that method from any
method in the derived class, as long as it is Public, Protected, Friend, or
Shared.

Now, if the method is not overridable, the derived class can actually, not
override it, but re-define it. This is what is referred to as "Shadowing" or
"Name-hiding." Generally, when you implement a method of the same name as a
base class method, in a derived class, and do not modify it with the Keyword
"Shadows," the program will compile, but the compiler will generate a
warning, to indicate that you have implicitly shadowed or hidden the member
of the same name in the base class. When a derived class hides or shadows a
method with the same name in a base class, the method is executed in the
derived class, but not in the base class, unless the derived class calls it
directly (as in "MyBase.Page_Load()"); Note that any method in a base class
may be shadowed (hidden) regardless of whether or not it is overridable.

I'm not sure why implicitly hiding or shadowing a member in a base class is
allowed. It often causes confusion, particularly in the cases of
inexperienced developers, or developers that are not using an IDE like
Visual Studio to create their apps, and cannot therefore see the
compiler-generated warning. But that is what Microsoft decided, for whatever
reasons. No doubt there was some discussion about it.

A bit more about shadowing: A method defined as "Shadows" does not have to
have the same signature (parameters and return type) as the method of the
same name in the base class. This is important, because of overloading.
Overloading is redefining a method with a different signature (parameters
and return type). Overloading a method in a base class, by changing its
signature, is not the same as Shadowing, or Name-hiding. So, if you overload
a method in a base class by creating a method with the same name and a
different signature, the base class's method is still available. It is
important to note this distinction, as there may be times when you want to
overload, and times when you may want to shadow, and it is best to do either
one intentionally!

So, if you define a method is a base class which you want to be Overridden,
it is best to define it as Overridable. You may then define the new version
of the method as Overrides. If you want a method to hide a member in the
base class, it is best to define it explictly as Shadows.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
I'd rather be a hammer than a nail.

"intrader" <in******@aol.com> wrote in message
news:pa****************************@aol.com... On Fri, 23 Sep 2005 14:31:52 -0700, Brock Allen wrote:
Reflection is used to find Page_Load, and the derived class' Page_Load is
hiding the base class'. I'd suggest having the base class override
OnLoad.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi all,

I have a site with the following architecture:

Common.Web.dll - Contains a CommonPageBase class which inherits
System.Web.UI.Page
myadd.dll - Contains PageBase which inherits CommonPageBase
- Contains myPage which inherits PageBase
Each of these classes overrides OnInit and ties an event handler
(Page_load) to the Load event.

The problem is that the Page_Load event is NOT being called in the
PageBase class, although it is in in myPage and CommonPageBase. I can
even step through the code that assigns the event handerl in
PageBase... but the Page_Load is still never called (all Page_Loads
are private).

Any ideas?

Thanks
Andy

Brock, could you explain this further?
Who is using Reflection?
Which derived class is hiding the base class

I really appreciate your explanation

Thanks

Nov 19 '05 #5
Brock,

I know I could override OnLoad, but I'd really like to know whats going
on here. CommonBasePage's Page_Load event is called, as is myPage's
Page_Load (both named the same, but marked private. Reflection seems
to be able to tell which class defined each method just fine). Even if
i change the code in PageBase so that Page_Load is called LoadIt and
LoadIt is tied to the Load event, it still does not fire. So I don't
think its a case of reflection not being able to find the method,
because there is nothing called LoadIt defined anywhere else.

Andy

Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: z. f. | last post by:
Hi, i have a class that is derived from System.Web.UI.Page, and this is the class i use in my application as PageBase. all other page classes are deriverd from my PageBase instead of the...
0
by: z. f. | last post by:
Hi, i have a asp.net (VB) web application. i my web form page i inherit from my own PageBase implementation instead of inheriting from web.ui.page. the PageBase is inheriting from web.ui.page...
11
by: fiefie.niles | last post by:
I am using ASP.NET 2005 and I have a simple form. Page_Load calls a sub mySub that does not do anything (for testing purposes). But, Page_Load gets called twice. On every single ASPX page in my...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.