Export (0) Print
Expand All
2 out of 3 rated this helpful - Rate this topic

Button Web Server Controls Content Map

Use the ASP.NET button Web server controls to enable users to post a page to the server. The button controls trigger an event in server code that you can handle to respond to the postback. For example, a user can indicate that they have completed a form or that they want to perform a specific command. The Button control can also raise an event in client script that you can handle before the page is posted or that can run and then cancel submission of the page.

ASP.NET includes several kinds of button controls, each of which appears differently on Web pages, as listed in the following table:

Control

Description

Button

Presents a standard command button, which is rendered as an HTML input element.

LinkButton

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 HyperLink Web server control.)

ImageButton

Renders a graphic as a button. This is useful for presenting a rich button appearance. The ImageButton control also provides information about the coordinates within the graphic where has clicked.

HtmlButton, HtmlInputButton, or HtmlInputImage

HTML button elements that you can program as ASP.NET Web server controls.

For information about the differences between HTML and Web server controls, see ASP.NET Web Server Controls Overview.

ImageMap

Lets you create a graphic that has hotspots that users can click to perform a postback or other action.

NoteNote

The ImageMap control lets you create a graphic that has hotspots that users can click in order to post a page or to perform other actions.

The following table lists tasks that are often performed using ASP.NET Web server button controls.

Scenario

Implementation

Respond to a button event.

Create a handler in server code for the button's Click event or Command event.

Determine which button among several caused the postback.

In a handler for the button's Click event or Command event, cast the source parameter to the appropriate type (Button, LinkButton, or ImageButton) and then get the ID of the object.

Run client script after a button is clicked and before the page is posted (for example, to display a confirmation message).

Add JavaScript code to the button's OnClientClick property. To cancel a postback in client script, return false from the client code.

Determine the coordinates in an image button where a user clicked.

Use an ImageButton control and in the button's Click event, get the X and Y values of the ImageClickEventArgs object that is passed to the event handler. For more information, see the example in the

In response to a button click, post to a different page than the one that the button is on.

Set the button's PostBackUrl property. For more information, see Redirecting Users to Another Page.

Specify whether a button click causes user input to be validated.

Enable or disable the button's CausesValidation property.

Determine which controls on the page perform validation in response to a button click.

Set the button's ValidationGroup property to match the name that is used with a validation control.

Configure a button to cause a partial-page postback.

Include the button inside an UpdatePanel control or put it outside the UpdatePanel control and set it to be a trigger. For more information, see UpdatePanel Control Overview and Partial-Page Rendering Overview.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.