order of execution of page_load in a base and derived classes

Discussion in 'ASP .Net' started by Ignacio Machin \( .NET/ C# MVP \), Sep 1, 2004.

  1. 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." <> wrote in message
    news:%...
    > 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.
    >
    >
     
    Ignacio Machin \( .NET/ C# MVP \), Sep 1, 2004
    #1
    1. Advertising

  2. Ignacio Machin \( .NET/ C#  MVP \)

    Karl Guest

    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." <> wrote in message
    news:%...
    > 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.
    >
    >
     
    Karl, Sep 1, 2004
    #2
    1. Advertising

  3. Re: order of execution of page_load in a base and derived classes II

    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." <> wrote in message
    news:%...
    > 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.
    >
    >
     
    Ignacio Machin \( .NET/ C# MVP \), Sep 1, 2004
    #3
  4. Re: order of execution of page_load in a base and derived classes II

    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.machin AT dot.state.fl.us> wrote
    in message news:#...
    > 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." <> wrote in message
    > news:%...
    > > 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.
    > >
    > >

    >
    >
     
    Benjamin Schwitter, Sep 1, 2004
    #4
  5. Ignacio Machin \( .NET/ C#  MVP \)

    z. f. Guest

    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.
     
    z. f., Sep 1, 2004
    #5
  6. Ignacio Machin \( .NET/ C#  MVP \)

    z. f. Guest

    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:...
    > 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." <> wrote in message
    > news:%...
    > > 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.
    > >
    > >

    >
    >
     
    z. f., Sep 1, 2004
    #6
  7. Ignacio Machin \( .NET/ C#  MVP \)

    z. f. Guest

    Re: order of execution of page_load in a base and derived classes II

    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.machin AT dot.state.fl.us> wrote
    in message news:%...
    > 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." <> wrote in message
    > news:%...
    > > 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.
    > >
    > >

    >
    >
     
    z. f., Sep 1, 2004
    #7
  8. Ignacio Machin \( .NET/ C#  MVP \)

    Karl Guest

    Can you show me some code? If I do this:

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    Trace.Write("derived load")
    end sub

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    Trace.Write("baseload")
    end sub

    the base load always fires first.

    Karl

    "z. f." <> wrote in message
    news:%...
    > 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:...
    > > 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." <> wrote in message
    > > news:%...
    > > > 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.
    > > >
    > > >

    > >
    > >

    >
    >
     
    Karl, Sep 1, 2004
    #8
  9. Ignacio Machin \( .NET/ C#  MVP \)

    z. f. Guest

    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:...
    > 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." <> wrote in message
    > news:%...
    > > 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.
    > >
    > >

    >
    >
     
    z. f., Sep 1, 2004
    #9
  10. 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." <> wrote in message
    news:...
    > 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:...
    > > 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." <> wrote in message
    > > news:%...
    > > > 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.
    > > >
    > > >

    > >
    > >

    >
    >
     
    Ignacio Machin \( .NET/ C# MVP \), Sep 1, 2004
    #10
  11. Re: order of execution of page_load in a base and derived classes II

    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." <> wrote in message
    news:...
    > 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.machin AT dot.state.fl.us>

    wrote
    > in message news:%...
    > > 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." <> wrote in message
    > > news:%...
    > > > 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.
    > > >
    > > >

    > >
    > >

    >
    >
     
    Ignacio Machin \( .NET/ C# MVP \), Sep 1, 2004
    #11
  12. Ignacio Machin \( .NET/ C#  MVP \)

    z. f. Guest

    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:...
    > 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." <> wrote in message
    > news:...
    > > 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:...
    > > > 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." <> wrote in message
    > > > news:%...
    > > > > 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.
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    z. f., Sep 2, 2004
    #12
  13. Ignacio Machin \( .NET/ C#  MVP \)

    Guest Guest

    "z. f." <> wrote in message
    news:%...
    > 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.
    >
    >


    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.Page
    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.
     
    Guest, Sep 2, 2004
    #13
  14. 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." <> wrote in message
    news:...
    > 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:...
    > > 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." <> wrote in message
    > > news:...
    > > > 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:...
    > > > > 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." <> wrote in message
    > > > > news:%...
    > > > > > 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.
    > > > > >
    > > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Ignacio Machin \( .NET/ C# MVP \), Sep 2, 2004
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. z. f.
    Replies:
    0
    Views:
    563
    z. f.
    Oct 19, 2004
  2. Colin Goudie
    Replies:
    6
    Views:
    477
    Victor Bazarov
    Jan 26, 2004
  3. Replies:
    4
    Views:
    415
    Alf P. Steinbach
    May 23, 2007
  4. Replies:
    1
    Views:
    397
    myork
    May 23, 2007
  5. Replies:
    1
    Views:
    390
    Victor Bazarov
    May 23, 2007
Loading...

Share This Page