Export (0) Print
Expand All

Introduction to the Button Web Server Controls

Visual Studio .NET 2003

Buttons on a Web Forms page allow users to indicate that they are finished with the form or want to perform a specific command. Web server controls include three kinds of buttons with different appearances.

Types of Buttons

You can create these types of Web server control buttons:

Button Web server control Presents a standard command button, rendered as an HTML submit button.
LinkButton Web server controlRenders as a hyperlink in the page. However, it contains client-side script that causes the form to be posted back to the server. (You can create a true hyperlink using the HyperLink Web server control.)
ImageButton Web server controlAllows you to specify a graphic as a button. This is useful for presenting a rich button appearance. ImageButton controls also pinpoint where in the graphic a user has clicked, which allows you to use the button as an image map.
Note   You can also use the HtmlButton and HtmlInputButton controls to create buttons on the page that are programmable in server code. For details about the differences between HTML and Web server controls, see Introduction to ASP.NET Server Controls.

Button Events

All three types of buttons cause a form to be submitted to the server when the user clicks them. This causes the page to be processed and any pending events to be raised in server-based code. The buttons can also raise their own Click events that you can write event handlers for.

Buttons in Container Controls

Button Web server controls are often used in other controls, such as in the DataList, DataGrid, and Repeater list controls. When they are, you generally respond to their events differently than when they are standing alone on a form. When a user clicks a button in a container control, the event message is bubbled to the container control, where it raises a container-specific event. For example, in the DataList control, a button often raises the DataList control's ItemCommand event (rather than a Button control's Click event).

Because the list Web server controls can contain many different buttons, you can specify an argument to pass along with the event when the event is bubbled to the container control. You can then test for this argument to see which button was clicked.

Binding Data to the Controls

You can bind the Web server button controls to a data source in order to control their property settings dynamically. For example, you can set the buttons' Text property via data binding.

For details, see Data Binding Single-Value Web Server Controls at Design Time.

See Also

Adding Button Web Server Controls to a Web Forms Page | Responding to Button Web Server Control Events | Creating Graphical Button Web Server Controls

© 2015 Microsoft