By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,974 Members | 1,834 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,974 IT Pros & Developers. It's quick & easy.

Difference between Page_Load and OnLoad

P: n/a
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}
}

Nov 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.

<lb********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.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}
}

Nov 19 '05 #2

P: n/a
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

Nov 19 '05 #3

P: n/a
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
..

<lb********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.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}
}

Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.