Web Server Controls->ASP.NET ImageButton Control
Definition and Usage
The ImageButton control is used to display a clickable image.
Properties
| Property | Description |
|---|---|
| CausesValidation | By default, a page is validated when a Button control is clicked. To prevent a page from being validated when clicking on a Button control, set this property to "false" |
| Command | The command associated with the Command event |
| CommandArgument | Additional information about the command to perform |
| id | A unique id for the control |
| ImageUrl | The URL of the image to display |
| OnClick | The name of the function to be executed when the image is clicked |
| runat | Specifies that the control is a server control. Must be set to "server" |
Examples
ImageButton
ASPX Source:
| <script runat="server"> Sub getCoordinates(sender As Object, e As ImageClickEventArgs) mess.Text="Coordinates: " & e.x & ", " & e.y End Sub </script> <html> <body> <form runat="server"> <p>Click on the image:</p> <asp:ImageButton runat="server" ImageUrl="smiley.gif" OnClick="getCoordinates"/> <p><asp:label id="mess" runat="server"/></p> </form> </body> </html> |
Output Result:
|
Click on the image: |
If you click the image ,it will show:
|
Click on the image: Coordinates: 23, 9 |
In this example we declare one ImageButton control and one Label control in an .aspx file. When the user clicks on the image, the getCoordinates subroutine is executed. The subroutine sends the message "Coordinates: " and the x and y coordinates of the click to the Label control.
浙公网安备 33010602011771号