System.Web.UI.WebControls Namespace ImageButton Class
Sets or retrieves an optional parameter passed to the Command event along with the associated CommandName.
Inline |
<asp:imagebutton commandargument = strValue ... > |
Script |
ImageButton.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 ImageButton is clicked. For example, a CommandName property set to Sort may have a CommandArgument property set to Ascending, so the code can handle the command appropriately.
The following example demonstrates how to set the CommandArgument property at design time, to create an ImageButton control that sorts a list in ascending order.
<form runat = "server">
<asp:imagebutton id = "myImageButton" runat = "server"
imageurl = "sort.jpg"
commandname = "Sort"
commandargument = "Ascending"
onCommand = "getCommandArgs" />
</form>
The below example demontrates an Command event handler that, in this case, simply determines the event arguments passed to the handler when an ImageButton 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 + " imagebutton.";
}
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 & " imagebutton."
End Sub |
|
C# |
VB |
ImageButton Members Command Event