Page_Load in derived classes

J

John Grandy

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 ?
 
G

Guest

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top