ImageButton.Click Evento

Definição

Ocorre quando o ImageButton é clicado.

public:
 event System::Web::UI::ImageClickEventHandler ^ Click;
public event System.Web.UI.ImageClickEventHandler Click;
member this.Click : System.Web.UI.ImageClickEventHandler 
Public Custom Event Click As ImageClickEventHandler 

Tipo de evento

Exemplos

O exemplo a seguir demonstra como especificar e codificar um manipulador para o Click evento para exibir as coordenadas nas quais o usuário clica na imagem.

Observação

O exemplo de código a seguir usa o modelo de código de arquivo único e pode não funcionar corretamente se copiado diretamente em um arquivo code-behind. Este exemplo de código deve ser copiado para um arquivo de texto vazio que tenha uma extensão .aspx. Para obter mais informações sobre o modelo de código Web Forms, consulte ASP.NET Web Forms Modelo de Código de Página.

<%@ 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 Sample</title>
<script language="C#" runat="server">

      void ImageButton_Click(object sender, ImageClickEventArgs e) 
      {
         Label1.Text = "You clicked the ImageButton control at the coordinates: (" + 
                       e.X.ToString() + ", " + e.Y.ToString() + ")";
      }

   </script>

</head>

<body>

   <form id="form1" runat="server">

      <h3>ImageButton Sample</h3>

      Click anywhere on the image.<br /><br />

      <asp:ImageButton id="imagebutton1" runat="server"
           AlternateText="ImageButton 1"
           ImageAlign="left"
           ImageUrl="images/pict.jpg"
           OnClick="ImageButton_Click"/>

      <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 Sample</title>
<script language="VB" runat="server">

      Sub ImageButton_Click(sender As Object, e As ImageClickEventArgs) 
         Label1.Text = "You clicked the ImageButton control at the coordinates: (" & _ 
                       e.X.ToString() & ", " & e.Y.ToString() & ")"
      End Sub

   </script>

</head>

<body>

   <form id="form1" runat="server">

      <h3>ImageButton Sample</h3>

      Click anywhere on the image.<br /><br />

      <asp:ImageButton id="imagebutton1" runat="server"
           AlternateText="ImageButton 1"
           ImageAlign="left"
           ImageUrl="images/pict.jpg"
           OnClick="ImageButton_Click"/>

      <br /><br />
    
      <asp:label id="Label1" runat="server"/>

   </form>

</body>
</html>

Comentários

O Click evento é gerado quando o ImageButton controle é clicado.

Observação

Esse evento faz com que a página seja postada novamente no servidor.

Para obter mais informações sobre como lidar com eventos, consulte Como consumir eventos em um aplicativo Web Forms.

Aplica-se a

Confira também