asp.net.ph

Button.CommandArgument Property

System.Web.UI.WebControls Namespace   Button Class


Sets or retrieves an optional parameter passed to the Command event along with the associated CommandName.

Syntax


Inline <asp:button commandargument = strValue ... >
Script Button.CommandArgument = strValue

Property Value


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.

Remarks

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.

Example

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.";
}
  C# VB

See Also

Button Members   Command Event Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

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

You can help support asp.net.ph