Composite Control with Templates - DropDownList bubble events

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default Composite Control with Templates - DropDownList bubble events

    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


    Marc Castrechini Guest

  2. Similar Questions and Discussions

    1. Composite dropdownlist control that also displays a listbox????
      This is driving me crazy, I am trying to build a custom dropdownlist that when rendered also displays a listbox next to it. I am going to use the...
    2. Why is CreateChildControls called when a dropdownlist (of a composite control) selected index has changed
      That sums it up. When any of the dependent dropdown lists get their selected index changed (by user interaction) there is a new invocation of the...
    3. Composite control not raising events
      Hi, As for the Custom ComboBox control problem, here are some of my suggestions: 1. I think its better to dervied the ComboBox from the...
    4. Composite control events dont fire.
      Hello, I cannot figure out why this doesnt work. This is almost exactly the same as the samples I've seen but it doesnt work for me. I am...
    5. Capturing Events BEFORE CreateChildControls in Composite Control
      Lucas Tam <REMOVEnntp@rogers.com> wrote in news:Xns93DB5460A1D2Anntprogerscom@140.99.99.130: OK, I got LoadPostData to fire, however, my...
  3. #2

    Default Re: Composite Control with Templates - DropDownList bubble events

    > 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.


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


    Gaurav Vaish \(www.EduJiniOnline.com\) Guest

  4. #3

    Default RE: Composite Control with Templates - DropDownList bubble events

    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
    [url]http://msdn.microsoft.com/subscriptions/managednewsgroups/list.aspx[/url] 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
    [url]http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif[/url]
    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
    [url]http://msdn.microsoft.com/subscriptions/support/default.aspx[/url].
    ==================================================

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

    Walter Wang [MSFT] Guest

  5. #4

    Default Re: Composite Control with Templates - DropDownList bubble events

    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

    "Walter Wang [MSFT]" <wawang@online.microsoft.com> wrote in message
    news:B8cfq8G4GHA.400@TK2MSFTNGXA01.phx.gbl...
    > 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
    > [url]http://msdn.microsoft.com/subscriptions/managednewsgroups/list.aspx[/url] 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
    > [url]http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif[/url]
    > 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
    > [url]http://msdn.microsoft.com/subscriptions/support/default.aspx[/url].
    > ==================================================
    >
    > This posting is provided "AS IS" with no warranties, and confers no
    > rights.
    >

    Marc Castrechini Guest

  6. #5

    Default Re: Composite Control with Templates - DropDownList bubble events

    > 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'



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


    Gaurav Vaish \(www.EduJiniOnline.com\) Guest

  7. #6

    Default Re: Composite Control with Templates - DropDownList bubble events

    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] Guest

  8. #7

    Default Re: Composite Control with Templates - DropDownList bubble events

    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.

    Walter Wang [MSFT] Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139