O'Reilly logo

Programming Visual Basic .NET by Dave Grundgeiger

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required