Using ASP.NET button Web server controls on ASP.NET Web pages allows users to indicate that they have completed the form or that they want to perform a specific command. Web server controls include three kinds of buttons, each of which appears differently on Web pages.
Types of Buttons
The following table lists the types of buttons that you can create by using Web server controls.
Control | Description |
---|---|
|
Presents a standard command button, which is rendered as an HTML input element. |
|
Renders 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 by using the |
|
Allows you to specify a graphic as a button. This is useful for presenting a rich button appearance. The ImageButton controls also pinpoint where in the graphic a user has clicked, which allows you to use the button as an image map. |
![]() |
---|
You can also use the |
Button Events
When a user clicks any of the three types of buttons, a form is submitted to the server. This causes the Web page to be processed and any pending events to be raised in server-based code. The buttons can also raise their own
Button Controls and Validation
If a page contains ASP.NET validator controls, by default, clicking a button control causes the validator control to perform its check. If client-side validation is enabled for a validator control, the page is not submitted if a validation check has failed.
The following table describes the properties supported by button controls that enable you to control the validation process more precisely.
Property | Description |
---|---|
|
Specifies whether clicking the button also performs a validation check. Set this property to false to prevent a validation check. |
|
Allows you to specify which validators on the page are called when the button is clicked. If no validation groups are established, a button click calls all of the validators that are on the page. |
For more information, see Validating User Input in ASP.NET Web Pages.
Button Postback Behavior
When users click a button control, the page is posted back to the server. By default, the page is posted back to itself, where the same page is regenerated and the event handlers for controls on the page are processed.
You can configure buttons to post the current page to another page. This can be useful for creating multi-page forms. For details, see Cross-Page Posting in ASP.NET Web Pages.
By default, the Button control submits the page by using an HTML POST operation. The LinkButton and ImageButton controls cannot directly support an HTML POST operation. Therefore, when you use those buttons, they add client script to the page that allows the controls to submit the page programmatically. (The LinkButton and ImageButton controls therefore require that client script is enabled on the browser.)
Under some circumstances, you might want the Button control to also use client script to perform the postback. This can be useful if you want to programmatically manipulate the postback, such as attaching it to other elements on the page. You can set the Button control's
Handling Client-Side Events for Button Controls
Button controls can raise both server events and client events. Server events occur after postback, and they are handled in the server-side code that you write for the page. Client events are handled in client script, typically ECMAScript (JavaScript), and are raised before the page is submitted. By adding client-side events to ASP.NET button controls, you can perform tasks, such as displaying confirmation dialog boxes before submitting the page, and potentially canceling the submission. For details, see Client Script in ASP.NET Web Pages and How to: Respond to Button Web Server Control Events in Client Script.
Buttons in Data Controls
Button Web server controls are often used in data controls, such as in the
Because the list Web server controls can contain many different buttons, you can set the button's
Binding Data to the Controls
You can bind the button Web server controls to a data source in order to control their property settings dynamically. For example, you can set the buttons'
See Also
