Bubbling Events Up the Control Hierarchy

Posted by: 4GuysFromRolla.com Headlines, on 11 May 2005 | View original | Bookmarked: 0 time(s)

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, it's Command event is raised. But how does the DataGrid know when this event has been raised so that it can raise it's 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.

In this article we'll look at how, precisely, event bubbling works in ASP.NET. Event bubbling is a technique that all server control developers should be aware of. Additionally, it can be used as a means to pass event information from a User Control to its parent page, as discussed in Handle Events from Web User Controls (although personally I find it simpler to just use the technique of having the User Control raise its own events through the standard event firing syntax as discussed at An Extensive Examination of User Controls). Read on to learn more!
Read More >

Category: Events | Other Posts: View all posts by this blogger | Report as irrelevant | View bloggers stats | Views: 7336 | Hits: 231

Similar Posts

  • Silverlight 3 Released more
  • Going Controller-less in MVC: The Way Fowler Meant It To Be more
  • CodeDigest.Com Article,Codes,FAQs - April,2009 more
  • ViewModel with MVC/Navigation in Silverlight more
  • Easy way to create a web-based AJAX SFTP Client application more
  • ASP.NET MVC Controls and Good versus Evil more
  • ASP.NET Data Control Events more
  • Take Charge of Your Security more
  • How to use Ninject with ASP.NET MVC more
  • The DefaultButton Property - News To Me! more

News Categories

.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Data | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD