System.Web.UI.WebControls.ImageMap Class

Creates a control that displays an image on a page. When a hot spot region defined within the System.Web.UI.WebControls.ImageMap control is clicked, the control either generates a postback to the server or navigates to a specified URL.

See Also: ImageMap Members

Syntax

[System.ComponentModel.DefaultEvent("Click")]
[System.ComponentModel.DefaultProperty("HotSpots")]
[System.Web.UI.ParseChildren(true, "HotSpots")]
public class ImageMap : Image, System.Web.UI.IPostBackEventHandler

Remarks

In this topic:

Introduction

Use the System.Web.UI.WebControls.ImageMap control to create an image that contains defined hot spot regions. When a user clicks a hot spot region, the control can either generate a postback to the server or navigate to a specified URL. For example, you can use this control to display a map of a geographical region. When a user clicks a specific region on the map, the control navigates to a URL that provides additional data about the selected region. You can also use this control to generate a postback to the server and run specific code based on the hot spot region that was clicked. For example, you can use an System.Web.UI.WebControls.ImageMap control to capture user responses such as votes. When a user clicks the hot spot region defined for yes votes, code is called to record a yes response in a database. When a user clicks on the hot spot region defined for no votes, a no response is recorded. You can also mix these two scenarios within a single System.Web.UI.WebControls.ImageMap control. For example, you can specify one hot spot region to navigate to a URL and another hot spot region to post back to the server.

Use the Image.ImageUrl property to specify the path to the image to display for the System.Web.UI.WebControls.ImageMap control. You can define any number of System.Web.UI.WebControls.HotSpot objects within an System.Web.UI.WebControls.ImageMap control. You can use the System.Web.UI.WebControls.CircleHotSpot, System.Web.UI.WebControls.RectangleHotSpot, and System.Web.UI.WebControls.PolygonHotSpot classes to define hot spot regions. Alternatively, you can derive from the abstract System.Web.UI.WebControls.HotSpot class to define your own custom hot spot object.

There are two ways to specify the behavior of a System.Web.UI.WebControls.HotSpot object in an System.Web.UI.WebControls.ImageMap control when the System.Web.UI.WebControls.HotSpot is clicked. You can use either the ImageMap.HotSpotMode property on the System.Web.UI.WebControls.ImageMap control or the HotSpot.HotSpotMode property on an individual System.Web.UI.WebControls.HotSpot object. These properties are set using one of the System.Web.UI.WebControls.HotSpotMode enumeration values. If both properties are set, the HotSpot.HotSpotMode property specified on each individual System.Web.UI.WebControls.HotSpot object takes precedence over the ImageMap.HotSpotMode property on the System.Web.UI.WebControls.ImageMap control.

To navigate to a URL, set either the ImageMap.HotSpotMode property or the HotSpot.HotSpotMode property to HotSpotMode.Navigate. Use the HotSpot.NavigateUrl property to specify the URL to navigate to.

To generate a postback to the server, set either the ImageMap.HotSpotMode property or the HotSpot.HotSpotMode property to HotSpotMode.Postback. Use the HotSpot.PostBackValue property to specify a name for the hot spot region. This name will be passed in the System.Web.UI.WebControls.ImageMapEventArgs event data when a postback event occurs. When a postback System.Web.UI.WebControls.HotSpot is clicked, the ImageMap.Click event is raised. To programmatically control the actions performed when a postback System.Web.UI.WebControls.HotSpot is clicked, provide an event handler for the ImageMap.Click event.

To cause all System.Web.UI.WebControls.HotSpot objects in an System.Web.UI.WebControls.ImageMap control to have the same behavior, use the ImageMap.HotSpotMode property to specify the behavior. Then, either set the HotSpot.HotSpotMode property on each individual System.Web.UI.WebControls.HotSpot object to HotSpotMode.NotSet or do not specify a value for the HotSpot.HotSpotMode property.

To specify different behaviors for System.Web.UI.WebControls.HotSpot objects in an System.Web.UI.WebControls.ImageMap, set the HotSpot.HotSpotMode property on each individual System.Web.UI.WebControls.HotSpot object to either HotSpotMode.Navigate or HotSpotMode.PostBack.

Note:

If an System.Web.UI.WebControls.ImageMap control's ImageMap.HotSpotMode property or the HotSpot.HotSpotMode property on any of the System.Web.UI.WebControls.HotSpot objects it contains is set to HotSpotMode.NotSet or is not set to a value, by default the behavior is HotSpotMode.Navigate.

Accessibility

For information about how to configure this control so that it generates markup that conforms to accessibility standards, see Accessibility in Visual Studio 2010 and ASP.NET 4 and ASP.NET Controls and Accessibility.

Declarative Syntax

Example

<asp:ImageMap
    AccessKey="string"
    AlternateText="string"
    BackColor="color name|#dddddd"
    BorderColor="color name|#dddddd"
    BorderStyle="

Requirements

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in System.Web.dll)
Assembly Versions: 2.0.0.0
Since: .NET 2.0