Home All Groups Group Topic Archive Search About

Difference between Page_Load and OnLoad

Author
10 Jun 2005 12:28 AM
lbolognini@gmail.com
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}
}
---
public partial class AdminPage : Page
{
protected override void OnLoad(EventArgs e){//something here}
}

Author
10 Jun 2005 6:36 AM
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.

<lbologn***@gmail.com> wrote in message
Show quoteHide quote
news:1118363281.591550.288170@g14g2000cwa.googlegroups.com...
> 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}
> }
> ---
> public partial class AdminPage : Page
> {
> protected override void OnLoad(EventArgs e){//something here}
> }
>
Are all your drivers up to date? click for free checkup

Author
10 Jun 2005 9:44 AM
lbolognini@gmail.com
Peter Rilling wrote:
> 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
Author
10 Jun 2005 12:02 PM
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
..

<lbologn***@gmail.com> wrote in message
Show quoteHide quote
news:1118363281.591550.288170@g14g2000cwa.googlegroups.com...
> 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}
> }
> ---
> public partial class AdminPage : Page
> {
> protected override void OnLoad(EventArgs e){//something here}
> }
>

Bookmark and Share