Difference between Page_Load and OnLoad

  • Thread starter Thread starter lbolognini
  • Start date Start date
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}
}
 
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.
 
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
 
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
..
 
Back
Top