asp.net.ph

ImageButton.CommandName Property

System.Web.UI.WebControls Namespace   ImageButton Class


Sets or retrieves the command name associated with the ImageButton control that is passed to the Command event.

Syntax


Inline <asp:imagebutton commandname = strValue ... >
Script ImageButton.CommandName = strValue

Property Value


strValue String specifying the name of the command to perform when the ImageButton control is clicked.

The property is read/write with no default value.

Remarks

Use the CommandName property to specify or determine the command associated with an ImageButton control. This is particularly useful when a Web Forms page include multiple ImageButton controls.

You can set the CommandName property to any valid string that identifies the command to perform when an imagebutton is clicked. You can then programmatically determine the command name of the ImageButton control and handle the command appropriately.

You can also optionally pass additional information about the command by using the CommandArgument property.

Example

The following example demonstrates how to use the CommandName property 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.";
}
  C# VB

See Also

ImageButton 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