ImageButton.CommandArgument Propiedad

Definición

Obtiene o establece un argumento opcional que facilita información adicional sobre la propiedad CommandName.

public:
 property System::String ^ CommandArgument { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.Bindable(true)]
public string CommandArgument { get; set; }
[System.ComponentModel.Bindable(true)]
[System.Web.UI.Themeable(false)]
public string CommandArgument { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.CommandArgument : string with get, set
[<System.ComponentModel.Bindable(true)>]
[<System.Web.UI.Themeable(false)>]
member this.CommandArgument : string with get, set
Public Property CommandArgument As String

Valor de propiedad

String

Argumento opcional que complementa la propiedad CommandName.

Implementaciones

Atributos

Ejemplos

En el ejemplo siguiente se muestra cómo usar la CommandArgument propiedad para asociar un argumento de comando a un ImageButton control .

Nota

En el ejemplo de código siguiente se usa el modelo de código de un solo archivo y es posible que no funcione correctamente si se copia directamente en un archivo de código subyacente. Este ejemplo de código debe copiarse en un archivo de texto vacío que tenga una extensión .aspx. Para obtener más información sobre el modelo de código de Web Forms, vea modelo de código de página ASP.NET Web Forms.

<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>ImageButton CommandName Sample</title>
<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 id="form1" 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>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>ImageButton CommandName Sample</title>
<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 id="form1" 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>

Comentarios

A veces, varios ImageButton controles están relacionados y comparten el mismo valor para la CommandName propiedad, como Sort. Utilice esta propiedad para complementar la CommandName propiedad con información adicional sobre el comando que se va a realizar, como Ascending. Los valores de las CommandName propiedades y CommandArgument se usan normalmente en el OnCommand controlador de eventos para determinar la acción que se debe realizar cuando se hace clic en el ImageButton control.

Esta propiedad no se puede establecer mediante temas o temas de la hoja de estilos. Para obtener más información, vea ThemeableAttribute y ASP.NET Temas y máscaras.

Se aplica a

Consulte también