Handling(tracking) child controls events (only button type child controls) 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.
CODE:
Basically, to raise the event that you want bubbled up:
RaiseBubbleEvent(this, args);
And then to catch it:
protected override bool OnBubbleEvent(object source, EventArgs e) {
bool handled = false;
if (e is TemplatedListCommandEventArgs) {
TemplatedListCommandEventArgs ce = (TemplatedListCommandEventArgs)e;
OnItemCommand(ce);
handled = true;
}
return handled;
}
As the code implies, if this method returns false, the event will continue to bubble up the control hierarchy
LINK
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.
CODE:
Basically, to raise the event that you want bubbled up:
RaiseBubbleEvent(this, args);
And then to catch it:
protected override bool OnBubbleEvent(object source, EventArgs e) {
bool handled = false;
if (e is TemplatedListCommandEventArgs) {
TemplatedListCommandEventArgs ce = (TemplatedListCommandEventArgs)e;
OnItemCommand(ce);
handled = true;
}
return handled;
}
As the code implies, if this method returns false, the event will continue to bubble up the control hierarchy
LINK
No comments:
Post a Comment