ImageButton.Command Událost

Definice

Zobrazí se ImageButton při kliknutí na tlačítko.

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 

Event Type

Implementuje

Příklady

Následující příklad ukazuje, jak určit a kód obslužné rutiny události Command určit, na který ImageButton ovládací prvek je kliknut.

Poznámka

Následující ukázka kódu používá model kódu s jedním souborem a nemusí správně fungovat, pokud je zkopírován přímo do souboru kódu na pozadí. Tento vzorový kód musí být zkopírován do prázdného textového souboru s příponou .aspx. Další informace o modelu kódu Web Forms najdete v tématu ASP.NET Web Forms model kódu stránky.

<%@ 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>

Poznámky

Událost Command se vyvolá po ImageButton kliknutí na ovládací prvek.

Poznámka

Událost Command je vyvolána prostřednictvím hierarchie ovládacích BubbleEventprvků ve formě .

Poznámka

Tato událost způsobí, že se stránka publikuje zpět na server.

Další informace o zpracování událostí najdete v tématu Postupy: Využití událostí v aplikaci Web Forms.

Platí pro

Viz také