Concepts every .NET developer should understand

My understanding of useful features of .NET?

Bubbled events

leave a comment »

Ever heard of event bubbling concept in .NET? No, but don’t be surprised if you have used it (but just don’t know the term), here it is:-

Web server controls such as the Repeater, DataList, and DataGrid controls can contain button controls that themselves raise events. For example, each row in a DataGrid control can contain one or more buttons created dynamically by templates.

Rather than each button raising an event individually, events from the nested controls are bubbled — that is, they’re sent to the container. The container in turn raises a generic event called ItemCommand with parameters that allow you to discover which individual control raised the original event. By responding to this single event, you can avoid having to write individual event handlers for child controls. The ItemCommand event includes the two standard event arguments, an object referencing the source of the event and an event object containing event-specific information.

Note The DataGrid and DataList Web server controls support additional events, such as EditCommand, DeleteCommand, and UpdateCommand, which are special cases of bubbled events.
With buttons, you can use the CommandArgument property to pass a user-specified string to the event handler to help you identify what button raised the event. For example, in a DataList control, buttons raise the ItemCommand event. You can set the CommandArgument property of each button to a different value — perhaps one button’s value is “ShowDetails” and another button’s value is “AddToShoppingCart” and then capture those values in the event handler later.

Advertisement

Written by basaldotnet

May 26, 2010 at 5:46 pm

Posted in .NET Framework

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.