A control that displays an image and responds to mouse clicks on the image.
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _ <AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _ Public Class ImageButton _ Inherits Image _ Implements IPostBackDataHandler, IPostBackEventHandler, IButtonControl
Dim instance As ImageButton
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] public class ImageButton : Image, IPostBackDataHandler, IPostBackEventHandler, IButtonControl
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)] [AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)] public ref class ImageButton : public Image, IPostBackDataHandler, IPostBackEventHandler, IButtonControl
public class ImageButton extends Image implements IPostBackDataHandler, IPostBackEventHandler, IButtonControl
<asp:ImageButton />
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.
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.
The following code example demonstrates how to create an ImageButton control that displays the coordinates at which an image is clicked.
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="VB" AutoEventWireup="True" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html > <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>
<%@ 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 > <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="JScript" AutoEventWireup="True" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html > <head> <title>ImageButton Sample</title> <script language="JSCRIPT" runat="server"> function ImageButton_Click(sender : Object, e : ImageClickEventArgs) { 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>
for operating in a hosted environment. Demand value: LinkDemand. Permission value: Minimal.
for operating in a hosted environment. Demand value: InheritanceDemand. Permission value: Minimal.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98