Mark Olbert
2/5/2007 8:53:00 PM
I'm hazy on how event bubbling (and event handling, for that matter) and templated controls should work in a custom control. The
specific control I'm working on should have two properties set (SelectedValue and SelectedText) whenever the user makes a selection
within the control. This obviously isn't hard to do in a non-templated environment, or even in the "default" situation (because I
get to set exactly what controls get put in the default template, how their events are wired up, etc.).
But what do I do in the "real" templated situation where the webpage designer specifies some arbitrary control as the source for the
selection event? For example, the template instance might contain a listbox, a dropdown, a table full of linkbuttons, a gridview,
etc., etc. Not all of those items raise the same kind of event when a selection is made.
I know I can override OnBubbleEvent() and monitor the type of event argument passed in and/or the type of event sender to determine
how to repackage the selection into the format the custom control needs (or to just set those properties directly, for that matter).
But what if the template instance contained, say, multiple listboxes, only one of which was "the" selection listbox? How would I
distringuish between them?
When I've used other templated controls it looks like what happens is that I, as the webpage designer, write the event handler for
the control used in the template instance. In that handler method I either directly take action, or manually update the selected
value properties in the custom control, which might in turn raise a "selection changed" event that I handle elsewhere.
Is that basically the only thing I can do to ensure only "true" selection events get processed?
Conceptually, it seems like it would be useful if a template instance could specify the "embedded" control to listen to for
selection events. Is that possible/feasible?
- Mark