Handling Inherited Events

To handle an inherited event, override the protected OnEventName method inherited from the base class instead of attaching delegates. In general, the overridden method should call the OnEventName method of the base class to ensure that delegates attached to the event are invoked (unless you do not want to invoke the delegates). The following code fragment (from the Templated Control Sample) shows how a templated control handles its inherited DataBinding event to ensure that its child controls are created before invoking the data-binding event handlers.

protected override void OnDataBinding(EventArgs e) {
[VisualĀ Basic]
Protected Overrides Sub OnDataBinding(e As EventArgs)
End Sub

The following table shows the events that an ASP.NET server control inherits from Control and the methods to override if you want your control to handle that event.

Event To Handle Method to Override
Init OnInit
Load OnLoad
DataBinding OnDataBinding
PreRender OnPreRender
UnLoad OnUnLoad

See Also

Defining an Event | Handling and Raising Events