473,782 Members | 2,454 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

order of execution of page_load in a base and derived classes

Hi,

i have a class that is derived from System.Web.UI.P age, and this is the
class i use in my application as PageBase.
all other page classes are deriverd from my PageBase instead of the original
System.Web.UI.P age in order to have common checks in the page base.

i make securirty checks in the page base page_load event.
if the security fails, i can do whatever i want before the "real" / derived
page gets to be executed.

but i have noticed that the derived page load event gets to be called before
the base page load event.

so i have a problem.

i can cancel the use of page_load in my derived pages, but i use this
function to check on PostBack events that does not have server (like button)
event handler, but there when will i move it to?

is this the correct execution order - the derived gets to called before the
base?

is this also the order of execution in inheritence or only with delegated
event handlers? ( i mean when you use the syntax of Page.onLoad +=
this_onLoad )....

TIA, z.
Nov 16 '05
13 2584
Hi,

You add it where you need it. each page's method should be responsible to
handle the functionalities implemented on it. All you have to do is call the
method in the Page_Load.

Why is that not ok with you?

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"z. f." <zi**@info-scopeREMSPAM.co .il> wrote in message
news:es******** ******@TK2MSFTN GP15.phx.gbl...
i wouldn't like to add code to each page-class i add.
the idea behind using a PageBase is to not change the way i write the other pages, just let them use the services the PageBase implement without even
"knowing" anout it.
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote in message news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Hi again

I'm not very sure that the previous answer will solve the problem, IIRC
the order of execution of the handlers is not defined. therefore even ify
ou
register first the parent you may get the derived executing first after

all.

Therefore you have to use another approach, you could use a virtual

method
that you call in the OnLoad event, so each class Page) define what needs

to
be checked , being the trick to verify the parent first to have the

first line calling the parent method:
protected override Check()
{
parent.Check();
//do the checking
}

I think this will solve your problem.
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"z. f." <zi**@info-scopeREMSPAM.co .il> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi,

i have a class that is derived from System.Web.UI.P age, and this is the class i use in my application as PageBase.
all other page classes are deriverd from my PageBase instead of the

original
System.Web.UI.P age in order to have common checks in the page base.

i make securirty checks in the page base page_load event.
if the security fails, i can do whatever i want before the "real" /

derived
page gets to be executed.

but i have noticed that the derived page load event gets to be called

before
the base page load event.

so i have a problem.

i can cancel the use of page_load in my derived pages, but i use this
function to check on PostBack events that does not have server (like

button)
event handler, but there when will i move it to?

is this the correct execution order - the derived gets to called
before the
base?

is this also the order of execution in inheritence or only with

delegated event handlers? ( i mean when you use the syntax of Page.onLoad +=
this_onLoad )....

TIA, z.



Nov 16 '05 #11
you mean in c# don't you?
it is no question, it's a fact VB does it the way i showed, you can't
control it.

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
in message news:ux******** ******@tk2msftn gp13.phx.gbl...
Hi,

IIRC the Page_Load is added in the OnInit handler:

override protected void OnInit(EventArg s e)
{
InitializeCompo nent();
base.OnInit(e);
}
private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(this.Page_ Load);
}

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"z. f." <zi**@info-scopeREMSPAM.co .il> wrote in message
news:eF******** ******@TK2MSFTN GP15.phx.gbl...
also

from the IL created by VB compiler you see that in the constructor it is
adding the event handler:

Public Sub New()
AddHandler MyBase.Load, New EventHandler(Ad dressOf Me.Page_Load)
End Sub

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:uP******** ******@TK2MSFTN GP09.phx.gbl...
Please don't cross-post.

I'm assuming you are using C# 'cuz you wouldn't have this behaviour in
VB....anyways, the simplest solution is to go into your derived page's
OnInit function in the "Web Form Designer generated code" region, and

change
the order of the two executions:

InitializeCompo nent();
base.OnInit(e);

to

base.OnInit(e);
InitializeCompo nent();

This will cause the base page's init to load first, which will cause

it's Load event to get hooked up first, thus causing it to fire first.

Karl

"z. f." <zi**@info-scopeREMSPAM.co .il> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
> Hi,
>
> i have a class that is derived from System.Web.UI.P age, and this is the > class i use in my application as PageBase.
> all other page classes are deriverd from my PageBase instead of the
original
> System.Web.UI.P age in order to have common checks in the page base.
>
> i make securirty checks in the page base page_load event.
> if the security fails, i can do whatever i want before the "real" /
derived
> page gets to be executed.
>
> but i have noticed that the derived page load event gets to be called before
> the base page load event.
>
> so i have a problem.
>
> i can cancel the use of page_load in my derived pages, but i use this > function to check on PostBack events that does not have server (like
button)
> event handler, but there when will i move it to?
>
> is this the correct execution order - the derived gets to called before the
> base?
>
> is this also the order of execution in inheritence or only with

delegated
> event handlers? ( i mean when you use the syntax of Page.onLoad +=
> this_onLoad )....
>
> TIA, z.
>
>



Nov 16 '05 #12
"z. f." <zi**@info-scopeREMSPAM.co .il> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi,

i have a class that is derived from System.Web.UI.P age, and this is the
class i use in my application as PageBase.
all other page classes are deriverd from my PageBase instead of the original System.Web.UI.P age in order to have common checks in the page base.

i make securirty checks in the page base page_load event.
if the security fails, i can do whatever i want before the "real" / derived page gets to be executed.

but i have noticed that the derived page load event gets to be called before the base page load event.

so i have a problem.

i can cancel the use of page_load in my derived pages, but i use this
function to check on PostBack events that does not have server (like button) event handler, but there when will i move it to?

is this the correct execution order - the derived gets to called before the base?

is this also the order of execution in inheritence or only with delegated
event handlers? ( i mean when you use the syntax of Page.onLoad +=
this_onLoad )....

TIA, z.


Your classes dont work the way you would like. The ASPNET engine works with
your derived classes & calls the overriding methods in them, it couldn't
care about base classes ( I suppose it has to be System.Web.UI.P age
eventually) .
The effect you want only happens with new() where the 1st line in the
suboutine is either a call to one of the base classes constructors or an
implicit call to its parameterless constructor. So if you can put your
initialisation in the base classes new() then it should be fixed. However I
dont think all the ASP features are ready at that time, I also dont know if
any page object is reused for subsequent requests which could possibly lead
to some speedup but probably lead to hours of extra debugging. Maybe that
could be added by use of an attribute ?

--
Jonathan Bailey.
Nov 16 '05 #13
Hi,

Yes, the code I shown was in C#, I havent worked at all with VB but this is
the code the designer created :

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

I don;t know much about how the event is hooked , but I can bet it's done
in the constructor as you said.

Again the virtual method approach can help you in this escenario.

cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"z. f." <zi**@info-scopeREMSPAM.co .il> wrote in message
news:O7******** ******@TK2MSFTN GP12.phx.gbl...
you mean in c# don't you?
it is no question, it's a fact VB does it the way i showed, you can't
control it.

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote in message news:ux******** ******@tk2msftn gp13.phx.gbl...
Hi,

IIRC the Page_Load is added in the OnInit handler:

override protected void OnInit(EventArg s e)
{
InitializeCompo nent();
base.OnInit(e);
}
private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(this.Page_ Load);
}

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"z. f." <zi**@info-scopeREMSPAM.co .il> wrote in message
news:eF******** ******@TK2MSFTN GP15.phx.gbl...
also

from the IL created by VB compiler you see that in the constructor it is adding the event handler:

Public Sub New()
AddHandler MyBase.Load, New EventHandler(Ad dressOf Me.Page_Load)
End Sub

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:uP******** ******@TK2MSFTN GP09.phx.gbl...
> Please don't cross-post.
>
> I'm assuming you are using C# 'cuz you wouldn't have this behaviour in > VB....anyways, the simplest solution is to go into your derived page's > OnInit function in the "Web Form Designer generated code" region, and change
> the order of the two executions:
>
> InitializeCompo nent();
> base.OnInit(e);
>
> to
>
> base.OnInit(e);
> InitializeCompo nent();
>
> This will cause the base page's init to load first, which will cause

it's
> Load event to get hooked up first, thus causing it to fire first.
>
> Karl
>
> "z. f." <zi**@info-scopeREMSPAM.co .il> wrote in message
> news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
> > Hi,
> >
> > i have a class that is derived from System.Web.UI.P age, and this is
the
> > class i use in my application as PageBase.
> > all other page classes are deriverd from my PageBase instead of
the > original
> > System.Web.UI.P age in order to have common checks in the page base. > >
> > i make securirty checks in the page base page_load event.
> > if the security fails, i can do whatever i want before the "real" / > derived
> > page gets to be executed.
> >
> > but i have noticed that the derived page load event gets to be

called > before
> > the base page load event.
> >
> > so i have a problem.
> >
> > i can cancel the use of page_load in my derived pages, but i use this > > function to check on PostBack events that does not have server (like > button)
> > event handler, but there when will i move it to?
> >
> > is this the correct execution order - the derived gets to called

before
> the
> > base?
> >
> > is this also the order of execution in inheritence or only with
delegated
> > event handlers? ( i mean when you use the syntax of Page.onLoad +=
> > this_onLoad )....
> >
> > TIA, z.
> >
> >
>
>



Nov 16 '05 #14

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

Similar topics

13
1680
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 original System.Web.UI.Page in order to have common checks in the page base. i make securirty checks in the page base page_load event. if the security fails, i can do whatever i want before the "real" / derived page gets to be executed.
0
9639
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9479
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10311
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10146
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9942
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8967
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5509
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3639
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.