System.Web.UI.WebControls Namespace Button Class
Sets or retrieves an optional parameter passed to the Command event along with the associated CommandName.
Inline |
<asp:button commandargument = strValue ... > |
Script |
Button.CommandArgument = strValue |
strValue |
String specifying an optional parameter passed to the Command event along with the associated CommandName. |
The property is read/write with no default value.
Use the CommandArgument property to specify an optional parameter that complements the CommandName property.
NOTE: While you can set the CommandArgument property by itself, it is normally only used when the CommandName property is also set.
The CommandArgument property complements the CommandName property by allowing you to provide additional information about the action to perform when the Button is clicked.
For example, multiple button controls with their CommandName properties set to Sort may have one CommandArgument property set to Ascending and the other Descending. This provides an easy way to determine the appropriate action to perform in your Command event handler.
The following example demonstrates how to set the CommandArgument property at design time, to create a Button control that sorts a list in ascending order.
<form runat = "server">
<asp:button id = "myButton" runat = "server" text = "Sort"
commandname = "Sort"
commandargument = "Ascending"
onCommand = "getCommandArgs " />
</form>
The below example demontrates a Command event handler that, in this case, simply determines the event arguments passed to the handler when a Button is clicked.
void getCommandArgs ( Object src, CommandEventArgs e ) {
// insert code to sort in ascending order here.
msg.Text = "You clicked the " + e.CommandName +
" - " + e.CommandArgument + " button.";
}
Sub getCommandArgs ( src As Object, e As CommandEventArgs )
' insert code to sort in ascending order here.
msg.Text = "You clicked the " & e.CommandName & _
" - " & e.CommandArgument & " button."
End Sub |
|
C# |
VB |
Button Members Command Event