Ask a Question related to ASP.NET Building Controls, Design and Development.
-
Marc Castrechini #1
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
-
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... -
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... -
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... -
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... -
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... -
Gaurav Vaish \(www.EduJiniOnline.com\) #2
Re: Composite Control with Templates - DropDownList bubble events
> Does anyone have a reference or know how to override and bubble up the
You should look at overriding the method OnSelectedIndexChanged.> SelectedIndexChanged event?
The default implementation just raises the event.
Do you mean the newsgroup? No.> Final question, Is this group managed?
--
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
-
Walter Wang [MSFT] #3
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
-
Marc Castrechini #4
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
-
Gaurav Vaish \(www.EduJiniOnline.com\) #5
Re: Composite Control with Templates - DropDownList bubble events
> Do I understand correctly that only the button objects you listed support
It's for every 'Control'.> a Command event bubble? So I should use the recommended solution for all
> other objects (Datagrid, Lists objects, etc)?
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
-
Walter Wang [MSFT] #6
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
-
Walter Wang [MSFT] #7
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



Reply With Quote

