469,642 Members | 1,244 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,642 developers. It's quick & easy.

why Page_Load and OnLoad in VS, to protect developers?

Hi
I am aware of how Page_Load and OnLoad work. What I am curious about is
-why- there are 2 mechanisms for doing the same thing, in particular why
Visual Studio will generate code to implement the Page_Load functionality
and not OnLoad.
When should either be used?
My guess is that because OnLoad should call the base.OnLoad method its
slightly cleaner using the Page_Load mechanism but that sounds a bit
naff.

Any ideas?

Ta
F
Nov 17 '05 #1
2 3252
<fo******@yahoo.co.uk> wrote in message
news:ac**************************@posting.google.c om...
Hi
I am aware of how Page_Load and OnLoad work. What I am curious about is
-why- there are 2 mechanisms for doing the same thing, in particular why
Visual Studio will generate code to implement the Page_Load functionality
and not OnLoad.
When should either be used?
My guess is that because OnLoad should call the base.OnLoad method its
slightly cleaner using the Page_Load mechanism but that sounds a bit
naff.


Page_Load is a handler for the Load event. OnLoad is a virtual method called
during the load phase. You should call base.OnLoad from within your OnLoad
override, to allow base class functionality to work.

In particular, Control.OnLoad raises the Load event which is processed by
Page_Load.

A given event can be handled by more than one handler. This handler can be
in another class. You can only override a method from within a derived
class.
--
John Saunders
Internet Engineer
jo***********@surfcontrol.com
Nov 17 '05 #2
Page_Load is a handler for the Load event, which is generated in OnLoad.
OnLoad is inherited from Control (Page is derived from TemplateControl,
which is derived from Control).

Unless you are creating custom Page classes, you will generally stick with
the Page_OnLoad event handler instead of driving down into the methods
below.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************** ********************
Think Outside the Box!
************************************************** ********************
<fo******@yahoo.co.uk> wrote in message
news:ac**************************@posting.google.c om...
Hi
I am aware of how Page_Load and OnLoad work. What I am curious about is
-why- there are 2 mechanisms for doing the same thing, in particular why
Visual Studio will generate code to implement the Page_Load functionality
and not OnLoad.
When should either be used?
My guess is that because OnLoad should call the base.OnLoad method its
slightly cleaner using the Page_Load mechanism but that sounds a bit
naff.

Any ideas?

Ta
F

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Christian | last post: by
3 posts views Thread by Stevie_mac | last post: by
reply views Thread by RAJ | last post: by
2 posts views Thread by RAJ | last post: by
14 posts views Thread by V. Jenks | last post: by
2 posts views Thread by Dave | last post: by
3 posts views Thread by lbolognini | last post: by
5 posts views Thread by Andy | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.