LinkButton.Command Evento

Definición

Se produce cuando se hace clic en el control LinkButton.

public:
 event System::Web::UI::WebControls::CommandEventHandler ^ Command;
public:
 virtual event System::Web::UI::WebControls::CommandEventHandler ^ Command;
public event System.Web.UI.WebControls.CommandEventHandler Command;
member this.Command : System.Web.UI.WebControls.CommandEventHandler 
Public Custom Event Command As CommandEventHandler 

Tipo de evento

Implementaciones

Ejemplos

En el ejemplo siguiente se muestra cómo especificar y codificar un controlador para que el Click evento muestre un mensaje cuando se hace clic en el LinkButton control.

<%@ 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>LinkButton Command Event Example</title>
<script language="C#" runat="server">
     
      void LinkButton_Command(Object sender, CommandEventArgs e) 
      {
         Label1.Text = "You chose: " + e.CommandName + " Item " + e.CommandArgument;
      }
 
   </script>
 
</head>
<body>
 
   <form id="form1" runat="server">
 
      <h3>LinkButton Command Event Example</h3>
  
      <asp:LinkButton id="LinkButton1" 
           Text="Order Item 10001"
           CommandName="Order" 
           CommandArgument="10001" 
           OnCommand="LinkButton_Command" 
           runat="server"/>
 
      <br />
  
      <asp:LinkButton id="LinkButton2" 
           Text="Order Item 10002"
           CommandName="Order" 
           CommandArgument="10002" 
           OnCommand="LinkButton_Command" 
           Runat="server"/>
 
      <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>LinkButton Command Event Example</title>
<script language="VB" runat="server">
     
      Sub LinkButton_Command(sender As Object, e As CommandEventArgs) 
         Label1.Text = "You chose: " & e.CommandName & " Item " & _
            e.CommandArgument
      End Sub
 
   </script>
 
</head>
<body>
 
   <form id="form1" runat="server">
 
      <h3>LinkButton Command Event Example</h3>
  
      <asp:LinkButton id="LinkButton1" 
           Text="Order Item 10001"
           CommandName="Order" 
           CommandArgument="10001" 
           OnCommand="LinkButton_Command" 
           runat="server"/>
 
      <br />
  
      <asp:LinkButton id="LinkButton2" 
           Text="Order Item 10002"
           CommandName="Order" 
           CommandArgument="10002" 
           OnCommand="LinkButton_Command" 
           Runat="server"/>
 
      <br />
      <br />
 
      <asp:Label id="Label1" runat="server"/>
 
   </form>

</body>
</html>

Comentarios

El Command evento se genera cuando se hace clic en el LinkButton control. Este evento se usa normalmente cuando un nombre de comando, como Sort, está asociado al LinkButton control . Esto le permite crear varios LinkButton controles en una página web y determinar mediante programación qué LinkButton control se hace clic.

Nota

El Command evento se genera a través de la jerarquía de controles en forma de BubbleEvent.

Para obtener más información acerca de cómo controlar eventos, vea controlar y provocar eventos.

Se aplica a

Consulte también