Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Button Class
Collapse the table of content
Expand the table of content

Button Class

Displays a push button control on the Web page.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class Button : public WebControl, 
	IButtonControl, IPostBackEventHandler
<asp:Button />

Use the Button control to create a push button on the Web page. You can create either a Submit button or a Command button.

When you use a Button control, you typically write an event handler for the button's Click event or its Command event. These events are handled by using server-based code. This is different than events in traditional HTML pages or in client-based Web applications, where a button's onclick event is handled by using JavaScript that runs in the client. For more information, see ASP.NET Web Server Control Event Model.

By default, a Button control is a Submit button. A Submit button does not have a command name (specified by the CommandName property) associated with the button and simply posts the Web page back to the server. You can provide an event handler for the Click event to programmatically control the actions performed when the Submit button is clicked.

A Command button has a command name associated with the button, such as Sort, by setting the CommandName property. This allows you to create multiple Button controls on a Web page and programmatically determine which Button control is clicked. You can also use the CommandArgument property with a command button to provide additional information about the command to perform, such as Ascending. You can provide an event handler for the Command event to programmatically control the actions performed when the Command button is clicked.

By default, page validation is performed when a Button control is clicked. Page validation determines whether the input controls associated with a validation control on the page all pass the validation rules specified by the validation control. To prevent page validation from occurring, set the CausesValidation property to false.

Accessibility

The markup rendered by default for this control might not conform to accessibility standards such as the Web Content Accessibility Guidelines 1.0 (WCAG) priority 1 guidelines. For details about accessibility support for this control, see ASP.NET Controls and Accessibility.

TopicLocation
Walkthrough: Creating a Basic Control Designer for an ASP.NET Web Server ControlAuthoring ASP.NET Controls
How to: Respond to Button Web Server Control Events in Client ScriptBuilding ASP .NET Web Applications
How to: Connect Multiple Events to a Single Event Handler in ASP.NET Web PagesBuilding ASP .NET Web Applications
How to: Determine which Web Server Control Raised an EventBuilding ASP .NET Web Applications
How to: Add Button Web Server Controls to a Web Forms PageBuilding ASP .NET Web Applications
How to: Set Focus on ASP.NET Web Server ControlsBuilding ASP .NET Web Applications
How to: Add PlaceHolder Web Server Controls to a Web Forms PageBuilding ASP .NET Web Applications
How to: Respond to Button Web Server Control EventsBuilding ASP .NET Web Applications
How to: Respond to Button Events in Data-Bound ControlsBuilding ASP .NET Web Applications
How to: Respond to Button Events in DataList, Repeater, or GridView ItemsBuilding ASP .NET Web Applications
Walkthrough: Creating a Basic Control Designer for an ASP.NET Web Server ControlAuthoring ASP.NET Controls
How to: Respond to Button Web Server Control Events in Client ScriptBuilding ASP .NET Web Applications
How to: Connect Multiple Events to a Single Event Handler in ASP.NET Web PagesBuilding ASP .NET Web Applications
How to: Determine which Web Server Control Raised an EventBuilding ASP .NET Web Applications
How to: Add Button Web Server Controls to a Web Forms PageBuilding ASP .NET Web Applications
How to: Set Focus on ASP.NET Web Server ControlsBuilding ASP .NET Web Applications
How to: Add PlaceHolder Web Server Controls to a Web Forms PageBuilding ASP .NET Web Applications
How to: Respond to Button Web Server Control EventsBuilding ASP .NET Web Applications
How to: Respond to Button Events in Data-Bound ControlsBuilding ASP .NET Web Applications
How to: Respond to Button Events in DataList, Repeater, or GridView ItemsBuilding ASP .NET Web Applications
Walkthrough: Creating Reusable Elements with ASP.NET User ControlsBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Creating and Using ASP.NET Master Pages in Visual Web DeveloperBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Validating User Input in a Web Forms PageBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Customizing a Web Site Using Themes in Visual StudioBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Working with Cascading Style Sheet Styles in Visual Web DeveloperBuilding ASP .NET Web Applications in Visual Studio
How to: Create Event Handlers in ASP.NET Web Pages (Visual Studio)Building ASP .NET Web Applications in Visual Studio
Walkthrough: Data Binding to a Custom Business ObjectBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Creating a Basic Web Page in Visual Web DeveloperBuilding ASP .NET Web Applications in Visual Studio
How to: Add Button Web Server Controls to a Web Forms Page (Visual Studio)Building ASP .NET Web Applications in Visual Studio
Walkthrough: Using the ObjectDataSource with an XML File

The following code example demonstrates how to create a Submit Button control that posts the Web page content back to the server.

No code example is currently available or this language may not be supported.

The following code example demonstrates how to create a Command Button control that sorts a list.

No code example is currently available or this language may not be supported.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft