4
Reply

What is event bubbling in .NET?

Sapna

Sapna

13y
8.9k
0
Reply

    Simply calling a parent control's event from a child control is called Event bubbling. Handling child controls events through parent control in data bind controls known as event bubbling. Server controls like Datagrid, DataList, and Repeater can have other child controls inside them.Example DataGrid can have combo box inside datagrid. These child control do not raise there events by themselves, rather they pass the event to the container parent (which can be a datagrid, datalist, repeater), which passed to the page as "ItemCommand" event. As the child control send events to parent it is termed as event bubbling.

    Event bubbling is a concept which was used in ASP.Net DataBound controls like Grid and it is part of WPF. In case of WPF, suppose you have a Button inside a StackPanel. You can define click event handler at StackPanel. Normally, it checks for the handler at the control level and if it does not find it will move up the hierarchy i.e bubbles up and searches for the handler at StackPanel level and so on. Advantage is that, the same event handler defined once will control click for all buttons within the StackPanel.

    The ASP.NET page framework provides a technique called event bubbling that allows a child control to propagate events up its containment hierarchy. Event bubbling enables events to be raised from a more convenient location in the controls hierarchy and allows event handlers to be attached to the original control as well as to the control that exposes the bubbled event.

    Event bubbling is used by the data-bound controls (Repeater, DataList, and DataGrid) to expose command events raised by child controls (within item templates) as top-level events. While ASP.NET server controls in the .NET Framework use event bubbling for command events (events whose event data class derives from CommandEventArgs), any event defined on a server control can be bubbled.

    Sapna,

    Please take a look at the following.Thanks

    http://msdn.microsoft.com/en-us/library/aa719644(v=vs.71).aspx