Export (0) Print
Expand All

ImageButton Class

A control that displays an image and responds to mouse clicks on the image.

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

public class ImageButton : Image, IPostBackDataHandler, IPostBackEventHandler, IButtonControl
public class ImageButton extends Image implements IPostBackDataHandler, IPostBackEventHandler, 
	IButtonControl
public class ImageButton extends Image implements IPostBackDataHandler, IPostBackEventHandler, 
	IButtonControl

Use the ImageButton control to display an image that responds to mouse clicks.

Both the Click and Command events are raised when the ImageButton control is clicked.

By using the OnClick event handler, you can programmatically determine the coordinates where the image is clicked. You can then code a response, based on the values of the coordinates. Note that the origin (0, 0) is located at the upper left corner of the image.

You can use the OnCommand event handler to make the ImageButton control behave like a Command button. A command name can be associated with the control by using the CommandName property. This allows multiple ImageButton controls to be placed on the same Web page. The value of the CommandName property can then be programmatically identified in the OnCommand event handler to determine the appropriate action to perform when each ImageButton control is clicked. The CommandArgument property can also be used to pass additional information about the command, such as specifying ascending order.

By default, page validation is performed when an ImageButton control is clicked. Page validation determines whether the input controls associated with a validation control on the page all pass the validation rules specified by the validation control. To prevent page validation from occurring, set the CausesValidation property to false.

Accessibility

The markup rendered by default for this control might not conform to accessibility standards such as the Web Content Accessibility Guidelines 1.0 (WCAG) priority 1 guidelines. For details about accessibility support for this control, see ASP.NET Controls and Accessibility.

TopicLocation
How to: Respond to Button Web Server Control Events in Client ScriptBuilding ASP .NET Web Applications
How to: Add a Login Button to an ASP.NET Web PageBuilding ASP .NET Web Applications
How to: Add Button Web Server Controls to a Web Forms PageBuilding ASP .NET Web Applications
How to: Set Focus on ASP.NET Web Server ControlsBuilding ASP .NET Web Applications
How to: Add ImageButton Web Server Controls to a Web Forms PageBuilding ASP .NET Web Applications
How to: Respond to Button Web Server Control EventsBuilding ASP .NET Web Applications
How to: Respond to Button Events in Data-Bound ControlsBuilding ASP .NET Web Applications
How to: Respond to Button Events in DataList, Repeater, or GridView ItemsBuilding ASP .NET Web Applications
How to: Determine Coordinates in an ImageButton Web Server ControlBuilding ASP .NET Web Applications
How to: Respond to Button Web Server Control Events in Client ScriptBuilding ASP .NET Web Applications
How to: Add a Login Button to an ASP.NET Web PageBuilding ASP .NET Web Applications
How to: Add Button Web Server Controls to a Web Forms PageBuilding ASP .NET Web Applications
How to: Set Focus on ASP.NET Web Server ControlsBuilding ASP .NET Web Applications
How to: Add ImageButton Web Server Controls to a Web Forms PageBuilding ASP .NET Web Applications
How to: Respond to Button Web Server Control EventsBuilding ASP .NET Web Applications
How to: Respond to Button Events in Data-Bound ControlsBuilding ASP .NET Web Applications
How to: Respond to Button Events in DataList, Repeater, or GridView ItemsBuilding ASP .NET Web Applications
How to: Determine Coordinates in an ImageButton Web Server ControlBuilding ASP .NET Web Applications
Walkthrough: Creating and Using ASP.NET Master Pages in Visual Web DeveloperBuilding ASP .NET Web Applications in Visual Studio
How to: Add ImageButton Web Server Controls to a Web Forms Page (Visual Studio)Building ASP .NET Web Applications in Visual Studio
Walkthrough: Data Binding to a Custom Business ObjectBuilding ASP .NET Web Applications in Visual Studio
How to: Add Button Web Server Controls to a Web Forms Page (Visual Studio)Building ASP .NET Web Applications in Visual Studio

The following code example demonstrates how to create an ImageButton control that displays the coordinates at which an image is clicked.

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 Page Code Model.

<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<head>

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


System.Object
   System.Web.UI.Control
     System.Web.UI.WebControls.WebControl
       System.Web.UI.WebControls.Image
        System.Web.UI.WebControls.ImageButton

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft