Difference between Page_Load and OnLoad

L

lbolognini

Hi everybody,

sorry for the newbie question but I can't get the difference between
these two code snippets. Is it that one is a delegate (the first) and
that while the first ADDS behaviour the other completely rewrites it?

Thanks,
Lorenzo

public partial class AdminPage : Page
{
protected void Page_Load(object sender, EventArgs e){//something here}
}
 
P

Peter Rilling

You are correct. The really provide the same functionality to the code, but
only the class itself can implement OnLoad. Anything outside must use the
Load event and map it to a method. If you use the OnLoad method, you must
call the base class's OnLoad, otherwise the event handlers will not be
called.
 
L

lbolognini

Peter said:
You are correct. The really provide the same functionality to the code, but
only the class itself can implement OnLoad. Anything outside must use the
Load event and map it to a method. If you use the OnLoad method, you must
call the base class's OnLoad, otherwise the event handlers will not be
called.

Hi Peter,

thanks for the reply

Lorenzo
 
T

Teemu Keiski

Yes,

Load is the event and OnLoad is a method that raises that event when called
it's just base class implementation that does it of course, and therefore
needs to be called from deriving classes so that events work)

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
..
 

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

Top