473,769 Members | 5,724 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 #1
13 2583
Hi,

I have never been in this situation, but the first thing I would try is in
the Form.OnInit move the base.OnInit to the start of the method, before
register the Load handler for the current page.

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 #2
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 #3
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 #4
i use vb.net
and i don't override the OnInit method in my PageBase.

"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 #5
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 #6
We had the same problem with the Page_Load Event.

We solved it similar to the way Ignacio Machin describes using the OnLoad
event.

Good luck,

Benjamin Schwitter

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
in message news:#n******** ******@tk2msftn gp13.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 #7
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 #8
Can you show me some code? If I do this:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Trace.Write("de rived load")
end sub

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Trace.Write("ba seload")
end sub

the base load always fires first.

Karl

"z. f." <zi**@info-scopeREMSPAM.co .il> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
i use vb.net
and i don't override the OnInit method in my PageBase.

"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 #9
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 #10

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
9589
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...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8870
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...
1
7408
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3958
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.