|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Correct place to add an event handler in code?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 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 <wald***@gmail.com> ha scritto nel messaggio Show quoteHide quote news:1154445735.666828.185440@h48g2000cwc.googlegroups.com... > 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 > 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). -- Show quoteHide quoteTeemu Keiski ASP.NET MVP, AspInsider Finland, EU http://blogs.aspadvice.com/joteke <wald***@gmail.com> wrote in message news:1154445735.666828.185440@h48g2000cwc.googlegroups.com... > 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 > 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 Teemu Keiski wrote: Show quoteHide quote > 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).
Events fired from dynamically created controls-VB.net
Set property in user control Dynamic button event not firing C# Literal control rendering empty Referencing a parent control from a child? Adding layout elements within custom control customizing the dropdown menu of combo box in asp.net dropdownlist System.Data.SQLClient IValidator and Validation Groups |
|||||||||||||||||||||||