Button Controls
Buttons are controls that post the form back to the server, enabling server-side processing to commence. There are three types of button controls:
Button |
LinkButton |
ImageButton |
In addition to the properties, methods, and events inherited along with all the other ASP controls, all three button types have the following two events:
- Click
Raised when control is clicked and no command name is associated with the button (that is, no value has been assigned to the Button control’s CommandName property). The method is passed an argument of type EventArgs.
- Command
Raised when the control is clicked and a command name is associated with the button (that is, a command name has been assigned to the Button control’s CommandName property). The event is passed an argument of type CommandEventArgs, which has the following two members:
- CommandName
The name of the command
- CommandArgument
An optional argument for the command
The code in Example 5-5 and Example 5-6 creates a web page containing three buttons, one of each type. Each button performs the same task: transferring control to another web page. Example 5-5 shows the C# code, and Example 5-6 shows the same code in VB.NET.
Note
In order for the code in Example 5-5 and Example 5-6 to work correctly, you must have a target web
page to link to. This can be any valid .htm
,
.asp
or .aspx
file. In
these examples, the target page is hard-coded as
TargetPage.aspx
, located in the
ProgAspNet
virtual directory. In addition, you will need ...
Get Programming ASP.NET, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.