Skip to content
February 5, 2011 / pauldundon

Handling Events from a Collection of Buttons

The Problem: You have an ASP.NET web page or server control which contains several buttons (perhaps dynamically generated). You want to handle the Click event on these without adding a handler for each one.

The Solution: Override OnBubbleEvent in your page or control. When a button control raises a Click event which is not handled, it invokes OnBubbleEvent on its parents, passing the arguments from the original Click event. OnBubbleEvent is raised for each parent in the control hierarchy in turn until one of them returns False.

You can use a combination of the sender object’s ID and the CommandName and CommandArgument in the EventArgs to determine which button was clicked and what action to take.

Advertisements

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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: