Yikes! Where is that initialization code in ASPNET 2.0?

P

PinoyDotnet

I am just starting 2.0, so I have this


In ASPNET 1.X there is a method called InitializeComponent() which
clearly wires in the Page_Load method to the Load event, like this:

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}

(1)
However, in ASPNET 2.0, you will not see this anymore. How am I suppose
to know the Page_Load is the correct method? Do you know where they
are hiding the code?


(2)
You can put the Page_Load method, and it is guaranteed to be called.
However, I noticed that even if I put the wrong signature such as:

void Page_Load()


It is still called anyway. Why is that?

(Note: Load event has this signature: void Load(object,
System.EventArgs )


ASPNET 2.0 gurus please clarify!

Thanks
 
G

Guest

(2)
doesn't the specific load function has the signature "handles Page_Load"
orso tailing behind the function ? (so there's where they make a difference
from the other methods)
 
B

Brock Allen

(1)
However, in ASPNET 2.0, you will not see this anymore. How am I
suppose
to know the Page_Load is the correct method? Do you know where they
are hiding the code?

There are several methods that are automatically called based upon naming
convention. This list is well documented. This was the way it was in v1.x
as well. The three important ones are:

Page_PreInit
Page_Init
Page_Load

IIRC, there are about ten in total. With Reflector, go check out the code
for System.Web.UI.TemplateControl.HookUpAutomaticHandlersWithNoAssert.
(2)
You can put the Page_Load method, and it is guaranteed to be called.
However, I noticed that even if I put the wrong signature such as:
void Page_Load()

It is still called anyway. Why is that?

This too was supported in v1.x. It's just a convenience.
 

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,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top