The following example creates an event, named Click, that adds and removes handlers from the control's EventHandlerList collection when the event is called from a page.
Note This example optimizes how a control adds and removes events from the list of them that the control maintains. If you create custom control and want to define an event, use code similar to this. This technique can be used in C#, but not in Visual Basic.
|
// Create an event that adds and removes handlers from the
// Control.Events collection when this event is called from
// a participating page.
public event EventHandler Click {
add {
Events.AddHandler(EventClick, value);
}
remove {
Events.RemoveHandler(EventClick, value);
}
}
|