[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.buildingcontrols

Event Bubbling and Templated Controls

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
5 Answers

stcheng

2/6/2007 9:27:00 AM

0

Hello Mark,

For your scenario, the two properties(SelectedValue and SelectedText) need
to be updated according to some sub controls(in a Template) which is not
predefined, I agree that there is no perfect means here which can either
let the user put whatever controls they like in the template and let our
main custom control correctly update the two properties depend on those
unpredictable child control's events.

So far what I can get are the following options:

** If your custom control is designed to only support limited type of
controls (such as ListBox and DropDownList or TextBox) to raise change
event so as to change the SelectedValue and SelectedText properties, I
think you can consider check the control type (by the source ) of the
OnBubbleEvent to determine whether you need to call function to update the
properties.


** Another means is that you add some additional properties, such as a
"ChilldID" string property and a "ControlType" property. You'll have to let
the users of your custom control to set these two properties. These two
properties indicate the ID of the control in the template whose postback
event need to trigger the changing of the SelectedValue and SelectedText
property, and the type of that control in template. Thus, in your control's
OnBubbleEvent, you can check the source control with the two additional
properties to determine whether to do the modification.

How do you think on this? If you have any other ideas or questions on
this, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default....
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/de....

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.




Mark Olbert

2/7/2007 1:25:00 AM

0

Steven,

Thanks for the reply. In continuing to work the problem I developed
something similar to your second approach. I augmented it a bit by
specifying a ControlID property, an Event name property, and a pair of
value properties (because I'm passing along both selected value and
selected text properties). I use reflection to see if each control in
a template matches the specs (in an overridden AddedControl() method
-- that may not be the precise name, I'm writing this from memory).

One other question I had was whether it was possible to specify that
the template itself could "hold" the properties I use to match the
selection control. Right now the various "selection" properties (e.g.,
ControlID) are exposed by the custom control itself, not the template.
It would be a bit cleaner if the template specification in the .aspx
file held those properties. In other words, I'd like to do this:

<cc1:MyCustomControl ....>
<ItemTemplate ControlID="lbxSelector">
....
</ItemTemplate>
...
</cc1:MyCustomControl>

rather than this, which is what I'm doing today:

<cc1:MyCustomControl ControlID="lbxSelector" ....>
<ItemTemplate>
....
</ItemTemplate>
...
</cc1:MyCustomControl>

But I'm not sure if this is possible in a custom template class. Do
you know if it is?

- Mark

On Feb 6, 1:26 am, stch...@online.microsoft.com (Steven Cheng[MSFT])
wrote:
> Hello Mark,
>
> For your scenario, the two properties(SelectedValue and SelectedText) need
> to be updated according to some sub controls(in a Template) which is not
> predefined, I agree that there is no perfect means here which can either
> let the user put whatever controls they like in the template and let our
> main custom control correctly update the two properties depend on those
> unpredictable child control's events.
>
> So far what I can get are the following options:
>
> ** If your custom control is designed to only support limited type of
> controls (such as ListBox and DropDownList or TextBox) to raise change
> event so as to change the SelectedValue and SelectedText properties, I
> think you can consider check the control type (by the source ) of the
> OnBubbleEvent to determine whether you need to call function to update the
> properties.
>
> ** Another means is that you add some additional properties, such as a
> "ChilldID" string property and a "ControlType" property. You'll have to let
> the users of your custom control to set these two properties. These two
> properties indicate the ID of the control in the template whose postback
> event need to trigger the changing of the SelectedValue and SelectedText
> property, and the type of that control in template. Thus, in your control's
> OnBubbleEvent, you can check the source control with the two additional
> properties to determine whether to do the modification.
>
> How do you think on this? If you have any other ideas or questions on
> this, please feel free to post here.
>
> Sincerely,
>
> Steven Cheng
>
> Microsoft MSDN Online Support Lead
>
> ==================================================
>
> Get notification to my posts through email? Please refer tohttp://msdn.microsoft.com/subscriptions/managednewsgroups/d......
> ications.
>
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) athttp://msdn.microsoft.com/subscriptions/support/de....
>
> ==================================================
>
> This posting is provided "AS IS" with no warranties, and confers no rights.


stcheng

2/7/2007 1:29:00 PM

0

Thanks for your reply Mark,

As for the template coupled properties, based on my research, the current
template model in ASP.NET doesn't support this. This is because when you
specify the template content in aspx template, at runtime, the ASP.NET page
will always parse it through a fixed template based "ITemplate" interface's
derived class unless you explictily use code to assign a custom Itemplate
derived class. Thus, we are not able to add additional properties on
template. For your scenario, do you think it would be better if we use
some composite property to group all those small properties associated to a
certain template. For example, suppose we have some properties which are
specific to HeaderTemplate, then we define a composite class named
"headerSettings" which contains many sub properties and let this type be
one of the composite control's top level properties. How do you think?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.



Mark Olbert

2/7/2007 4:22:00 PM

0

That would work, too. Given that what I have now works, though, I think I'll stick with it.

Thanks for following up.

- Mark

On Wed, 07 Feb 2007 13:29:27 GMT, stcheng@online.microsoft.com (Steven Cheng[MSFT]) wrote:

>Thanks for your reply Mark,
>
>As for the template coupled properties, based on my research, the current
>template model in ASP.NET doesn't support this. This is because when you
>specify the template content in aspx template, at runtime, the ASP.NET page
>will always parse it through a fixed template based "ITemplate" interface's
>derived class unless you explictily use code to assign a custom Itemplate
>derived class. Thus, we are not able to add additional properties on
>template. For your scenario, do you think it would be better if we use
>some composite property to group all those small properties associated to a
>certain template. For example, suppose we have some properties which are
>specific to HeaderTemplate, then we define a composite class named
>"headerSettings" which contains many sub properties and let this type be
>one of the composite control's top level properties. How do you think?
>
>Sincerely,
>
>Steven Cheng
>
>Microsoft MSDN Online Support Lead
>
>
>This posting is provided "AS IS" with no warranties, and confers no rights.
>
>

msb

10/16/2013 8:14:00 PM

0


Mark Brader:
> > Scores, if there are no errors...

Stephen Perry:
> I did not enter because I saw other people's answers first.

I don't think that constitutes an error in the scoreboard.
--
Mark Brader | "How is freedom gained? It is taken: never given.
Toronto | To be free, you must first assume your right
msb@vex.net | to freedom." -- Salman Rushdie