This documentation is archived and is not being maintained.

Handling Inherited Events

.NET Framework 1.1

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) {
    EnsureChildControls();
    base.OnDataBinding(e);
}
[Visual Basic]
Protected Overrides Sub OnDataBinding(e As EventArgs)
   EnsureChildControls()
   MyBase.OnDataBinding(e)
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 HandleMethod to Override
InitOnInit
LoadOnLoad
DataBindingOnDataBinding
PreRenderOnPreRender
UnLoadOnUnLoad

See Also

Defining an Event | Handling and Raising Events

Show: