aspnet2005: What is Page_Load ?

  • Thread starter Thread starter Ernest Morariu
  • Start date Start date
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
 
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
 
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
 
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




Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
 
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
 
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
 
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
 
Back
Top