Page_Load in derived classes

Discussion in 'ASP .Net' started by John Grandy, Aug 6, 2007.

  1. John Grandy

    John Grandy Guest

    If I have UserControlDervied that derives from another UserControlBase , and
    in UserControlBase the OnLoad method is overriden , is it necessary to also
    override the OnLoad method in UserControlDerived , or can the magic
    Page_Load method be used ? Does Page_Load automatically call OnLoad in any
    underlying class ?
     
    John Grandy, Aug 6, 2007
    #1
    1. Advertising

  2. John,

    Page_Load is an event which is called by base class, whereas OnLoad is an
    override which is executed instead of the base method.

    To summarise:
    Page_Load event is called in both classes (it is up to the programmer
    whether to supply a handler and in which class); those events are independent
    and the execution order cannot be guaranteed.

    OnLoad overrides base class method, and the code is executed in the
    inherited class. It is up to the programmer whether to call base class
    (OnLoad) method - which is usually a good practice as there may be other
    listeners attached to that.
    In this case the programmer can decide whether to execute the custom code
    before or after calling the base method.

    "John Grandy" wrote:

    > If I have UserControlDervied that derives from another UserControlBase , and
    > in UserControlBase the OnLoad method is overriden , is it necessary to also
    > override the OnLoad method in UserControlDerived , or can the magic
    > Page_Load method be used ? Does Page_Load automatically call OnLoad in any
    > underlying class ?
    >
    >
    >
     
    =?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?=, Aug 6, 2007
    #2
    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. Ignacio Machin \( .NET/ C#  MVP \)

    order of execution of page_load in a base and derived classes

    Ignacio Machin \( .NET/ C# MVP \), Sep 1, 2004, in forum: ASP .Net
    Replies:
    13
    Views:
    922
    Ignacio Machin \( .NET/ C# MVP \)
    Sep 2, 2004
  2. z. f.
    Replies:
    0
    Views:
    589
    z. f.
    Oct 19, 2004
  3. Colin Goudie
    Replies:
    6
    Views:
    508
    Victor Bazarov
    Jan 26, 2004
  4. Replies:
    1
    Views:
    419
    myork
    May 23, 2007
  5. Replies:
    1
    Views:
    405
    Victor Bazarov
    May 23, 2007
Loading...

Share This Page