ASP.NET Syntax ASP.NET Syntax for Web Controls
Displays a push button control on the Web Forms page.
Declarative Syntax
<asp:Button
AccessKey = "string"
BackColor = "color name | #dddddd"
BorderColor = "color name | #dddddd"
BorderStyle = "NotSet | None | Dotted | Dashed | Solid | Double | Groove |
Ridge | Inset | Outset"
BorderWidth = size
CausesValidation = "True | False"
CommandArgument = "string"
CommandName = "string"
CssClass = "string"
Enabled = "True | False"
EnableTheming = "True | False"
EnableViewState = "True | False"
Font-Bold = "True | False"
Font-Italic = "True | False"
Font-Names = "string"
Font-Overline = "True | False"
Font-Size = "string | Smaller | Larger | XX-Small | X-Small | Small |
Medium | Large | X-Large | XX-Large"
Font-Strikeout = "True | False"
Font-Underline = "True | False"
ForeColor = "color name | #dddddd"
Height = size
ID = "string"
OnClick = "Click event handler"
OnClientClick = "string"
OnCommand = "Command event handler"
OnDataBinding = "DataBinding event handler"
OnDisposed = "Disposed event handler"
OnInit = "Init event handler"
OnLoad = "Load event handler"
OnPreRender = "PreRender event handler"
OnUnload = "Unload event handler"
PostBackUrl = "uri"
runat = "server"
SkinID = "string"
Style = "string"
TabIndex = integer
Text = "string"
ToolTip = "string"
UseSubmitBehavior = "True | False"
ValidationGroup = "string"
Visible = "True | False"
Width = size
/>
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.
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.
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.";
}
Sub commandHandler ( sender As Object, e As CommandEventArgs )
Message.Text = "You clicked the " & e.CommandName & _
" - " & e.CommandArgument & " button."
End Sub |
|
C# |
VB |
Button Class Button Web Server Controls