Defining and Raising Events

By default, your user control doesn't raise any of its own specific events—it only raises events defined by its base class (UserControl), such as the Load and Unload events. If you want to add your own events, such as the SelectedIndexChanged event, you'll need to add a little more code to the user control's code-behind file.

You'll first need to define the event, adding a declaration for the event including its parameters and return value. Then, you'll need to manually raise the event so that the consumers of your control can react to the event.

TIP

The code you're about to add hasn't really changed from VB6, if you've ever raised an event from a class in VB6. You may have noticed the use of the WithEvents keyword ...

Get ASP.NET Developer's JumpStart now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.