Correct place to add an event handler in code?

W

waldenl

I've got a control on my page (in this case a repeater) that I want to
add an event handler to (in this case I want to handle ItemDataBound).
I know I could add the control declaritively, but to be honest, i'm
lazy and want VS 2005 to create the handler definition for me so I want
to use the += convention so it generates the handler stub. Where's the
"correct" place to put this code? In the Page_Load event?

I know it will probably work in several places, but I'm looking for the
"correct" place to use it.

-Walden
 
A

Alessandro Zifiglio

hi Walden,
protected void Page_Init(object sender, EventArgs e)
{

}
For dynamic controls creation, Page_Init is the right place to add controls
to the pages controls collection and also hookup any necessary events, this
way your dynamic control will participate well in the pages control life
cycle for the proper loading of viewstate, postback data and you have what.

Regards,
Alessandro Zifiglio
http://www.AsyncUI.net
 
T

Teemu Keiski

If you add it declaratively in design view, you can also add the event
handler via property browser (select the lighting symbol when control is
selected) by clicking from the list of available events when same handler is
generated for you. If I'd add event handlers in code, I'd put them in OnInit
(Page_Init).
 
W

WaldenL

Yes, but that only works from w/in design view, not from w/in code view
of the html, and when dealing w/repeaters it's not always easy/possible
to select the repeater control in the design view. And if you select it
by changing the drop down in the properties view then the event button
(lightning bolt) doesn't show up.

-Walden
 

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,816
Messages
2,569,714
Members
45,502
Latest member
Andres34P

Latest Threads

Top