Re: order of execution of page_load in a base and derived classes
From: Ignacio Machin \( .NET/ C# MVP \) ("Ignacio)
Date: 09/02/04
- Next message: Cor Ligthert: "Re: mouse hoover"
- Previous message: Cor Ligthert: "Re: vb .net Message Box"
- In reply to: z. f.: "Re: order of execution of page_load in a base and derived classes"
- Next in thread: Ignacio Machin \( .NET/ C# MVP \): "Re: order of execution of page_load in a base and derived classes II"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 2 Sep 2004 09:59:06 -0400
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.EventArgs) 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." <zigi@info-scopeREMSPAM.co.il> wrote in message
news:O7dw5LLkEHA.3664@TK2MSFTNGP12.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.machin AT dot.state.fl.us>
wrote
> in message news:uxHOA4EkEHA.2788@tk2msftngp13.phx.gbl...
> > Hi,
> >
> > IIRC the Page_Load is added in the OnInit handler:
> >
> > override protected void OnInit(EventArgs e)
> > {
> > InitializeComponent();
> > base.OnInit(e);
> > }
> > private void InitializeComponent()
> > {
> > this.Load += new System.EventHandler(this.Page_Load);
> > }
> >
> >
> >
> > Cheers,
> >
> > --
> > Ignacio Machin,
> > ignacio.machin AT dot.state.fl.us
> > Florida Department Of Transportation
> >
> > "z. f." <zigi@info-scopeREMSPAM.co.il> wrote in message
> > news:eFyaQnCkEHA.2680@TK2MSFTNGP15.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(AddressOf Me.Page_Load)
> > > End Sub
> > >
> > >
> > >
> > >
> > >
> > > "Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote
> in
> > > message news:uP6eAICkEHA.1904@TK2MSFTNGP09.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:
> > > >
> > > > InitializeComponent();
> > > > base.OnInit(e);
> > > >
> > > > to
> > > >
> > > > base.OnInit(e);
> > > > InitializeComponent();
> > > >
> > > > 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." <zigi@info-scopeREMSPAM.co.il> wrote in message
> > > > news:%23GBK16BkEHA.2696@TK2MSFTNGP10.phx.gbl...
> > > > > 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.
> > > > >
> > > > > 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.
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
- Next message: Cor Ligthert: "Re: mouse hoover"
- Previous message: Cor Ligthert: "Re: vb .net Message Box"
- In reply to: z. f.: "Re: order of execution of page_load in a base and derived classes"
- Next in thread: Ignacio Machin \( .NET/ C# MVP \): "Re: order of execution of page_load in a base and derived classes II"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|