ImageButton.CommandArgument Property
Gets or sets an optional argument that provides additional information about the CommandName property.
[Visual Basic] Public Property CommandArgument As String [C#] public string CommandArgument {get; set;} [C++] public: __property String* get_CommandArgument(); public: __property void set_CommandArgument(String*); [JScript] public function get CommandArgument() : String; public function set CommandArgument(String);
Property Value
An optional argument that supplements the CommandName property.
Remarks
Sometimes, multiple ImageButton controls are related and share the same value for the CommandName property, such as Sort. Use this property to supplement the CommandName property with additional information about the command to perform, such as Ascending. The values of the CommandName and CommandArgument properties are typically used in the OnCommand event handler to determine the action to perform when the ImageButton control is clicked.
Example
[Visual Basic, C#, JScript] The following example demonstrates how to use the CommandArgument property to associate a command argument with an ImageButton control.
[Visual Basic] <%@ Page Language="VB" AutoEventWireup="True" %> <html> <head> <script language="VB" runat="server"> Sub ImageButton_Command(sender As Object, e As CommandEventArgs) If (e.CommandName = "Sort") And (e.CommandArgument = "Ascending") Then Label1.Text = "You clicked the Sort Ascending Button" Else Label1.Text = "You clicked the Sort Descending Button" End If End Sub </script> </head> <body> <form runat="server"> <h3>ImageButton CommandName Sample</h3> Click an image.<br><br> <asp:ImageButton id="imagebutton1" runat="server" AlternateText="Sort Ascending" ImageUrl="images/pict.jpg" OnCommand="ImageButton_Command" CommandName="Sort" CommandArgument="Ascending"/> <asp:ImageButton id="imagebutton2" runat="server" AlternateText="Sort Descending" ImageUrl="images/pict2.jpg" OnCommand="ImageButton_Command" CommandName="Sort" CommandArgument="Descending"/> <br><br> <asp:label id="Label1" runat="server"/> </form> </body> </html> [C#] <%@ Page Language="C#" AutoEventWireup="True" %> <html> <head> <script language="C#" runat="server"> void ImageButton_Command(object sender, CommandEventArgs e) { if (e.CommandName == "Sort" && e.CommandArgument == "Ascending") Label1.Text = "You clicked the Sort Ascending Button"; else Label1.Text = "You clicked the Sort Descending Button"; } </script> </head> <body> <form runat="server"> <h3>ImageButton CommandName Sample</h3> Click an image.<br><br> <asp:ImageButton id="imagebutton1" runat="server" AlternateText="Sort Ascending" ImageUrl="images/pict.jpg" OnCommand="ImageButton_Command" CommandName="Sort" CommandArgument="Ascending"/> <asp:ImageButton id="imagebutton2" runat="server" AlternateText="Sort Descending" ImageUrl="image/pict2.jpg" OnCommand="ImageButton_Command" CommandName="Sort" CommandArgument="Descending"/> <br><br> <asp:label id="Label1" runat="server"/> </form> </body> </html> [JScript] <%@ Page Language="JScript" AutoEventWireup="True" %> <html> <head> <script language="JSCRIPT" runat="server"> function ImageButton_Command(sender : Object, e : CommandEventArgs){ if(e.CommandName == "Sort" && e.CommandArgument == "Ascending") Label1.Text = "You clicked the Sort Ascending Button" else Label1.Text = "You clicked the Sort Descending Button" } </script> </head> <body> <form runat="server"> <h3>ImageButton CommandName Sample</h3> Click an image.<br><br> <asp:ImageButton id="imagebutton1" runat="server" AlternateText="Sort Ascending" ImageUrl="images/pict.jpg" OnCommand="ImageButton_Command" CommandName="Sort" CommandArgument="Ascending"/> <asp:ImageButton id="imagebutton2" runat="server" AlternateText="Sort Descending" ImageUrl="images/pict2.jpg" OnCommand="ImageButton_Command" CommandName="Sort" CommandArgument="Descending"/> <br><br> <asp:label id="Label1" runat="server"/> </form> </body> </html>
[C++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
See Also
ImageButton Class | ImageButton Members | System.Web.UI.WebControls Namespace | CommandName | OnCommand | Button | Image