ImageButton.Click Event

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Occurs when the ImageButton is clicked.

Namespace:   System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public event ImageClickEventHandler Click

The Click event is raised when the ImageButton control is clicked.

System_CAPS_noteNote

This event causes the page to be posted back to the server.

For more information about handling events, see How to: Consume Events in a Web Forms Application.

The following example demonstrates how to specify and code a handler for the Click event to display the coordinates at which the user clicks the image.

System_CAPS_noteNote

The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information on the Web Forms code model, see ASP.NET Web Forms Page Code Model.

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

.NET Framework
Available since 1.1
Return to top
Show: