asp.net.ph

Skip Navigation Links

Button Control Syntax

ASP.NET Syntax   ASP.NET Syntax for Web Controls


Displays a push button control on the Web Forms page.

Declarative Syntax

NOTE: The content of an <asp:Button> control can be defined within its opening tag. In this case, you can close the start tag with a trailing slash /> instead of a separate end tag.

For information on the individual members of this class, see Button in the class library.

Remarks

The Button control renders a push button on a Web Forms page. There are two types of buttons that can be created. You can create either a submit button or a command 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. By default, a Button control is a submit button. 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 Forms page and programmatically determine which Button control is clicked in the event handler for the Click event. You can also use the CommandArgument property with a command button to provide addition 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.

Syntax Example

The following example demonstrates the declaration for a submit button control in an .aspx file.

<asp:Button id="SubmitButton"
   Text = "Submit"
   onClick = "submitHandler"
   runat="server" />

The following example demonstrates the declaration for a command button control in an .aspx file.

<asp:Button id="SortAscendingButton"
   Text = "Sort Ascending"
   CommandName = "Sort"
   CommandArgument = "Ascending"
   onClick = "commandHandler"
   runat="server" />

The following example shows an event-handling method that gets the button click and displays the information passed from the button in its CommandName and CommandArgument properties.

void commandHandler ( Object sender, CommandEventArgs e ) {
   Message.Text = "You clicked the " + e.CommandName +
      " - " + e.CommandArgument + " button.";
}
  C# VB

See Also

Button Class   Button Web Server Controls



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note