[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

Composite Control with Templates - DropDownList bubble events

Marc Castrechini

9/22/2006 8:01:00 PM

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


6 Answers

MasterGaurav \(www.edujini-labs.com\)

9/24/2006 4:36:00 AM

0

> 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 | http://www.master...
http://www.edujini...
http://articles.edujinionline.com/w...
-------------------


wawang

9/25/2006 6:52:00 AM

0

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... 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....
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/de....
==================================================

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

Marc Castrechini

9/26/2006 2:45:00 PM

0

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
> http://msdn.microsoft.com/subscriptions/managednewsgroups... 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....
> 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/de....
> ==================================================
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>


MasterGaurav \(www.edujini-labs.com\)

9/26/2006 5:48:00 PM

0

> 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 | http://www.master...
http://www.edujini...
http://articles.edujinionline.com/w...
-------------------


wawang

9/27/2006 2:25:00 AM

0

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.

wawang

9/29/2006 9:23:00 AM

0

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.