aspnet2005: What is Page_Load ?

E

Ernest Morariu

Hi All!

System.Web.UI.Page
C#

I do not understand what is the Page_Load method. I supose it is an event
handler for the Page.Load event, but I cannot find any association between
the event Page.Load and the method Page_Load.

I expected to find somewhere something like :
this.Load+=new EventHandler(this.Page_Load);

Can someone help me to understand how this method is called ?

Ernest
 
J

Jonathan

The ASP.NET page framework also supports an automatic way to associate
page events and methods. If the AutoEventWireup attribute of the Page
directive is set to true (or if it is missing, since by default it is
true), the page framework calls page events automatically, specifically
the Page_Init and Page_Load methods. In that case, no explicit Handles
clause or delegate is needed. [1]

[1]
http://msdn.microsoft.com/library/d.../en-us/vbcon/html/vbconWebFormsEventModel.asp
 
K

Karl Seguin [MVP]

In your @Page directive, there's an attribute called AutoWireUp when this
is true (which is the default behaviour in 2005), the compiler automatically
looks for certain method names and hooks them up. So internally, Page_Load
gets hooked into the Load event automatically.

Many of us prefer a different approach, set AutoWireUp to false and override
the onLoad event..

Karl
 
J

Juan T. Llibre

re:
I expected to find somewhere something like :
this.Load+=new EventHandler(this.Page_Load);

Can someone help me to understand how this method is called ?

In this page you'll find the answer to your questions :

"How to use the AutoEventWireup attribute in an ASP.NET Web Form"
http://support.microsoft.com/default.aspx?scid=kb;en-us;324151

Essentially, if you use AutoEventWireup="true",
you don't need to use the EventHandler code.

The Page_Load event is ideal for user code initialization:
http://msdn.microsoft.com/library/d...us/vbcon/html/vbconIntroductionToWebForms.asp

General info on ASP.NET internals is found at :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/Internals.asp
 
L

Laurent Bugnion

Hi Karl
Many of us prefer a different approach, set AutoWireUp to false and override
the onLoad event..

Karl

I would be interested to know what the advantages are to wire your
events yourself, instead of using AutoWireUp. Can you elaborate?

Thanks a lot,
Laurent
 
K

Karl Seguin [MVP]

Well, I've heard that there's a performance hit associated witht he
automatic hook up. It's probably quite trivial and I'd consider that an
unecessary micro-optimization. The real reason I do it is because
AutoWireUp is too obscur. It abstracts away well a understood and
established model - overriding and calling the base implementation. This can
lead to subtle bugs (in 1.1 a lot of people have page_load mysteriously fire
twice) as well as a harder-than-necesasry code to maintain. I've changed
my default templates so that AutoWireUp is false and my codebehind
automatically has the override code...so it's doesn't take me any more time.

I just don't see why this one case should be different than everything else
karl
 
L

Laurent Bugnion

Hi Karl,
Well, I've heard that there's a performance hit associated witht he
automatic hook up. It's probably quite trivial and I'd consider that an
unecessary micro-optimization. The real reason I do it is because
AutoWireUp is too obscur. It abstracts away well a understood and
established model - overriding and calling the base implementation. This can
lead to subtle bugs (in 1.1 a lot of people have page_load mysteriously fire
twice) as well as a harder-than-necesasry code to maintain. I've changed
my default templates so that AutoWireUp is false and my codebehind
automatically has the override code...so it's doesn't take me any more time.

I just don't see why this one case should be different than everything else
karl

Interesting. Thanks for the food for my thoughts ;-)

Laurent
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top