Handling Page Events

The base Page class may at times raise events. These events can be handled by the derived Page class (the code-behind class) or by code embedded in the web page. Although it’s possible to define an event-handler subroutine, the preferred response to events raised by the Page class is to override the protected methods provided by the Page class. For example, the following method could be placed in the code-behind class, providing a way to respond to the loading of the page:

Protected Overrides Sub OnLoad(e As EventArgs)
   MyBase.OnLoad(e)
   ' ...
End Sub

Warning

When overriding an OnEvent-style method, ensure that the overriding method calls the base-class implementation, in addition to its own processing. The job of the base-class implementation is to raise the corresponding event. If the base-class implementation is not called, the event won’t be raised.

Following is the list of events a Page object might raise. The Page class itself doesn’t define these events: it inherits them from its parent classes. This list of events includes a brief description of each event, the class in which the event is defined, and the syntax for overriding the protected method that corresponds to the event.

AbortTransaction (inherited from System.Web.UI.TemplateControl)

Raised when a COM+ transaction in which the page is participating is aborted. Its syntax is:

    Protected Overrides Sub OnAbortTransaction(ByVal e As EventArgs)
CommitTransaction (inherited from System.Web.UI.TemplateControl) ...

Get Programming Visual Basic .NET now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.