What is Event Bubbling ?

What is Event Bubbling ?

->Event Bubbling is nothing but events raised by child controls is handled by the parent control. Example: Suppose consider datagrid as parent control in which there are several child controls.There can be a column of link buttons right.Each link button has click event.Instead of writing event routine for each link button write one routine for parent which will handlde the click events of the child link button events.Parent can know which child actaully triggered the event.That thru arguments passed to event routine. Happy programming.

->The DataGrid control, as you likely know, can easily be configured to add a column of buttons. By adding a ButtonColumn, whenever one of the DataGrid’s buttons in the column is clicked, the Web page posts back and the DataGrid’s ItemCommand event fires. In fact, the same behavior can be noted if you manually add a Button or LinkButton control into a DataGrid TemplateColumn, as the ButtonColumn class simply adds a Button (or LinkButton) Web control to each row of the DataGrid.

–> When the Button (or LinkButton) is clicked, its Command event is raised. But how does the DataGrid know when this event has been raised so that it can raise its ItemCommand event in response? The answer is through a process referred to as event bubbling. Event bubbling is the process of moving an event up the control hierarchy, from a control low in the hierarchy – such as a Button within the row of a DataGrid – and percolating it up to an ancestor control – such as the DataGrid. Once the ancestor control has learned of the event it can respond however it sees fit; in the DataGrid’s case, the DataGrid “swallows” the Button’s Command event (that is, it stops the bubbling) and raises its own ItemCommand event in response.

->Server controls like Datagrid, DataList, Repeater can have other child controls inside them. Eg., a DataGrid can have combobox inside it. These child controls do not raise their 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 their events to parent this is termed as event bubbling.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

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

Google photo

You are commenting using your Google 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