472,331 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,331 software developers and data experts.

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 3320
<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: z. f. | last post by:
Hi, i have a class that is derived from System.Web.UI.Page, and this is the class i use in my application as PageBase. all other page classes...
3
by: Christian | last post by:
hi, what is the difference between the Page_Load() and OnLoad() event handlers. do they originate from a different point ?
3
by: Stevie_mac | last post by:
It might be me but... I dont seem to get a Page_Load event when a opening an ASPX in an iFrame. I do geta Page_Load event when an item on the...
0
by: RAJ | last post by:
This event appears to be invoked twice for absolutely no reason on only one of my ASP.Net web user controls. Although I've now overcome the problem...
2
by: RAJ | last post by:
Posting this thread again, can somebody please help me with this. Thanks. This event appears to be invoked twice for absolutely no reason on only...
14
by: V. Jenks | last post by:
I'm a little rusty having not touched .NET for 6 months and I can't remember why Page_Load is happening twice in this code: private void...
2
by: Dave | last post by:
Hi, this is a follow-up to an earlier question but I really haven't found a definitive answer in my search If I have a Base and Derived webform,...
3
by: lbolognini | last post by:
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...
5
by: Andy | last post by:
Hi all, I have a site with the following architecture: Common.Web.dll - Contains a CommonPageBase class which inherits System.Web.UI.Page...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.