O'Reilly logo

Programming ASP .NET by Dan Hurwitz, Jesse Liberty

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

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 (i.e., 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 (i.e., 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. Figure 5-3 shows the web page that results from running the example code.

Tip

In order for the code in Example 5-5 and Example 5-6 to work correctly, you need to 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 ...

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