473,320 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 3363
<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 are deriverd from my PageBase instead of the...
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 ASPX (inside the iFrame) is clicked but then...
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 by overriding the base classes OnLoad routine, I...
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 one of my ASP.Net web user controls. Although...
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 Page_Load(object sender, System.EventArgs e) {...
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, I've found that the dervived Page_Load event...
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 first) and that while the first ADDS behaviour 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 myadd.dll - Contains PageBase which inherits...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.