ASP.NET Syntax ASP.NET Syntax for Web Controls
Enables you to handle user clicks in an image, which gives you image map like functionality.
Declarative Syntax
<asp:ImageButton
AccessKey = "string"
AlternateText = "string"
BackColor = "color name | #dddddd"
BorderColor = "color name | #dddddd"
BorderStyle = "NotSet | None | Dotted | Dashed | Solid | Double | Groove |
Ridge | Inset | Outset"
BorderWidth = size
CausesValidation = "True | False"
CommandArgument = "string"
CommandName = "string"
CssClass = "string"
DescriptionUrl = "uri"
Enabled = "True | False"
EnableTheming = "True | False"
EnableViewState = "True | False"
ForeColor = "color name | #dddddd"
Height = size
ID = "string"
ImageAlign = "NotSet | Left | Right | Baseline | Top | Middle | Bottom |
AbsBottom | AbsMiddle | TextTop"
ImageUrl = "uri"
OnClick = "Click event handler"
OnClientClick = "string"
OnCommand = "Command event handler"
OnDataBinding = "DataBinding event handler"
OnDisposed = "Disposed event handler"
OnInit = "Init event handler"
OnLoad = "Load event handler"
OnPreRender = "PreRender event handler"
OnUnload = "Unload event handler"
PostBackUrl = "uri"
runat = "server"
SkinID = "string"
Style = "string"
TabIndex = integer
ToolTip = "string"
ValidationGroup = "string"
Visible = "True | False"
Width = size
/>
For information on the individual members of this class, see ImageButton in the class library.
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. These events always cause the page to be posted to the server.
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 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.
The following example demonstrates how to specify and code a handler for the Click event to display the coordinates where the user clicks the image.
Within the <head
> of the Web Forms page:
<script language="C#" runat="server">
void ImageButtonClickHandler ( object sender, ImageClickEventArgs e ) {
msgLabel.Text = "You clicked the ImageButton control at the coordinates: ( " +
e.X.ToString ( ) + ", " + e.Y.ToString ( ) + " ) ";
}
</script>
<script language="VB" runat="server">
Sub ImageButtonClickHandler ( sender As Object, e As ImageClickEventArgs )
msgLabel.Text = "You clicked the ImageButton control at the coordinates: ( " & _
e.X.ToString ( ) & ", " & e.Y.ToString ( ) & " ) "
End Sub
</script> |
|
C# |
VB |
Within the <body
> of the Web Forms page:
<form runat="server">
<asp:ImageButton id="imagebutton1" runat="server"
AlternateText = "ImageButton 1"
ImageAlign = "left"
ImageUrl = "images/pict.jpg"
onClick = "ImageButtonClickHandler" />
<p><asp:label id="msgLabel" runat="server" />
</form>
The following example demonstrates how to specify and code a handler for the Command event to determine which ImageButton control is clicked.
Within the <head
> of the Web Forms page:
<script language="C#" runat="server">
void ImageButtonCommandHandler ( object sender, CommandEventArgs e ) {
if ( e.CommandName == "Sort" && e.CommandArgument == "Ascending" )
msgLabel.Text = "You clicked the Sort Ascending Button";
else
msgLabel.Text = "You clicked the Sort Descending Button";
}
</script>
<script language="VB" runat="server">
Sub ImageButtonCommandHandler ( sender As Object, e As CommandEventArgs )
If ( e.CommandName = "Sort" ) And ( e.CommandArgument = "Ascending" ) Then
msgLabel.Text = "You clicked the Sort Ascending Button"
Else
msgLabel.Text = "You clicked the Sort Descending Button"
End If
End Sub
</script> |
|
C# |
VB |
Within the <body
> of the Web Forms page:
<form runat="server">
<asp:ImageButton id="imagebutton1" runat="server"
AlternateText = "Sort Ascending"
ImageUrl = "images/pict.jpg"
onCommand = "ImageButtonCommandHandler"
CommandName = "Sort"
CommandArgument = "Ascending" />
<asp:ImageButton id="imagebutton2" runat="server"
AlternateText = "Sort Descending"
ImageUrl = "images/pict2.jpg"
onCommand = "ImageButtonCommandHandler"
CommandName = "Sort"
CommandArgument = "Descending" />
<p><asp:label id="msgLabel" runat="server" />
</form>
ImageButton Class Button Web Server Controls