Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Building Controls / September 2006

Tip: Looking for answers? Try searching our database.

Composite Control with Templates - DropDownList bubble events

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marc Castrechini - 22 Sep 2006 21:01 GMT
I have a base composite control that uses templates.

If I add buttons (image, link, etc ..) to the template we can bubble the
event as an item command using the following ...
Protected Overrides Function OnBubbleEvent(ByVal source As Object, ByVal e
As EventArgs) As Boolean

If TypeOf e Is CommandEventArgs Then

Dim cmd As CommandEventArgs = CType(e, CommandEventArgs)

RaiseEvent ItemCommand(Me, New CommandEventArgs(cmd.CommandName,
cmd.CommandArgument))

Return True

End If

Return False

End Function

Does anyone have a reference or know how to override and bubble up the
SelectedIndexChanged event?

Please note that the Autopostback="True" in the template and I don't have a
member to wire up the event manually (although had considered looping
through the template controls to do so).

Final question, Is this group managed?

TIA,

- Castro
Gaurav Vaish (www.EduJiniOnline.com) - 24 Sep 2006 05:36 GMT
> Does anyone have a reference or know how to override and bubble up the
> SelectedIndexChanged event?

You should look at overriding the method OnSelectedIndexChanged.
The default implementation just raises the event.

> Final question, Is this group managed?

Do you mean the newsgroup? No.

Signature

Happy Hacking,
Gaurav Vaish | http://www.mastergaurav.com
http://www.edujinionline.com
http://articles.edujinionline.com/webservices
-------------------

Walter Wang [MSFT] - 25 Sep 2006 07:52 GMT
Hi Marc,

The concept of event bubbling means taking unhandled events and shooting
them up the chain of parent controls until they reach the surface. Event
bubbling does not happen magically, it must be order by the controls when
they fire their events. In the case of built-in ASP.NET controls, not all
events order bubbleing to take place. Button, LinkButton, and ImageButton
are those who do event bubbling. They have an event called Command. A
button's Click event does not automatically bubble up, but its Command
event does:

   Protected Overridable Sub OnClick(Byval e as EventArgs)
       RaiseEvent Click(Me, e)
   End Sub
   
   Protected Overridable Sub OnCommand(Byval e as CommandEventArgs)
       RaiseEvent Command(Me, e)
       RaiseBubbleEvent(Me, e)
   End Sub
   
The DropDownList does not do event bubbling by default. You will have to
create your own customized DropDownList to bubble event:

   Public Class MyDropDownList
       Inherits DropDownList

       Protected Overrides Sub OnSelectedIndexChanged(ByVal e As
System.EventArgs)
           MyBase.OnSelectedIndexChanged(e)
           MyBase.RaiseBubbleEvent(Me, New
CommandEventArgs("SelectedIndexChanged", Me))
       End Sub

   End Class

Using this customized DropDownList in your templates content, then you can
handle the ItemCommand event like this:

   Protected Sub t1_ItemCommand(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.CommandEventArgs) Handles t1.ItemCommand
       If e.CommandName = "SelectedIndexChanged" Then
           Dim ddl As DropDownList = CType(e.CommandArgument, DropDownList)
           Response.Write(ddl.SelectedItem.Value)
       End If
   End Sub

This newsgroup is managed. See
http://msdn.microsoft.com/subscriptions/managednewsgroups/list.aspx for a
complete list of managed newsgroups.

Sincerely,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

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/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Marc Castrechini - 26 Sep 2006 15:44 GMT
Thank you Walter,
Although I haven't implemented it yet I do understand your recommended
solution.

Do I understand correctly that only the button objects you listed support a
Command event bubble?  So I should use the recommended solution for all
other objects (Datagrid, Lists objects, etc)?

TIA,

- Marc

> Hi Marc,
>
[quoted text clipped - 74 lines]
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
Gaurav Vaish (www.EduJiniOnline.com) - 26 Sep 2006 18:47 GMT
> Do I understand correctly that only the button objects you listed support
> a Command event bubble?  So I should use the recommended solution for all
> other objects (Datagrid, Lists objects, etc)?

It's for every 'Control'.
RaiseBubbleEvent method is defined in the class 'Control'

Signature

Happy Hacking,
Gaurav Vaish | http://www.mastergaurav.com
http://www.edujinionline.com
http://articles.edujinionline.com/webservices
-------------------

Walter Wang [MSFT] - 27 Sep 2006 03:24 GMT
Hi Marc,

For the built-in web controls, three of them are bubbling event by default:
Button, ImageButton, and LinkButton.

If you use Reflector to run command "Analyzer" on Control.RaiseBubbleEvent,
you will see these:

* Button.OnCommand
* ImageButton.OnCommand
* LinkButton.OnCommand

OnCommand will be used by RaisePostBackEvents which means it will gets
called when it's clicked and posted back.

* DataGridItem.OnBubbleEvent
* DataListItem.OnBubbleEvent
* DetailsViewRow.OnBubbleEvent
* FormViewRow.OnBubbleEvent
* GridViewRow.OnBubbleEvent
* Menu.OnBubbleEvent
* MenuItemTemplateContainer.OnBubbleEvent
* RepeaterItem.OnBubbleEvent

These are actually good examples of how to bubbling up the events when you
received bubbled event from your templated contents. Use RepeaterItem for
example, when you put a control which is calling RaiseBubbleEvent inside
the template, what you need to do is to override OnBubbleEvent and bubble
them up again. The bubbled event from RepeaterItem will be handled in
Repeater's overridden OnBubbleEvent:

Protected Overrides Function OnBubbleEvent(ByVal sender As Object, ByVal e
As EventArgs) As Boolean
     Dim flag1 As Boolean = False
     If TypeOf e Is RepeaterCommandEventArgs Then
           Me.OnItemCommand(DirectCast(e, RepeaterCommandEventArgs))
           flag1 = True
     End If
     Return flag1
End Function

I hope this helps you understand how the event bubbling works. For your
last question, other than the Button, LinkButton, ImageButton controls, all
other controls are not bubbling event up by default.

I understand that your initial requirement is to handle controls' events
which are placed inside your control's templates. Besides using event
bubbling, you can use FindControl to find the controls inside the template
using their ID, and hook up its event handler dynamically.

Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Walter Wang [MSFT] - 29 Sep 2006 10:23 GMT
Hi Marc,

I am interested in this issue. Would you mind letting me know the result of
the suggestions? If you need further assistance, feel free to let me know.
I will be more than happy to be of assistance.

Have a great day!

Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.