1. Home
  2. Computing & Technology
  3. Visual Basic

Learn ASP.NET 2.0 - ASP.NET 2.0 Server Controls
The Web Server Control Event Subroutine

By , About.com Guide

Apr 13 2008

Visual Studio programmers will be glad to hear that Microsoft has done a great job of making the techniques that work in Windows forms event subroutines also work in Web forms. For example, the same sender and e parameters work the same way and the Handles clause does too.

For example, consider the simple website with three buttons and a label shown below:

--------
Click Here to display the illustration
Click the Back button on your browser to return
--------

The following code shows how a common subroutine can handle all three buttons using the Handles clause and the Sender parameter.

Protected Sub Button_Click( _
   ByVal sender As Object, _
   ByVal e As System.EventArgs) _
   Handles Button1.Click, Button2.Click, Button3.Click
   Label1.Text = sender.Text
End Sub

The Button control doesn't pass anything using the e parameter but other controls do. For example, the ImageButton control passes the X and Y coordinates. It's necessary to check the documentation of the control to find out what might be passed.

Explore Visual Basic
By Category
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic
  4. Learn VB.NET
  5. Learn ASP.NET
  6. Learn ASP.NET 2.0 - ASP.NET 2.0 Server Controls

©2009 About.com, a part of The New York Times Company.

All rights reserved.