.NET Framework Class Library ImageMap Class Creates a control that displays an image on a page. When a hot spot region defined within the ImageMap control is clicked, the control either generates a postback to the server or navigates to a specified URL.

Inheritance Hierarchy
Namespace:
System.Web.UI.WebControls
Assembly:
System.Web (in System.Web.dll)

Syntax
Public Class ImageMap _
Inherits Image _
Implements IPostBackEventHandler
public class ImageMap : Image, IPostBackEventHandler
public ref class ImageMap : public Image,
IPostBackEventHandler
type ImageMap =
class
inherit Image
interface IPostBackEventHandler
end
The ImageMap type exposes the following members.

Constructors
|
| Name | Description |
|---|
.gif) | ImageMap | Initializes a new instance of the ImageMap class. | Top

Methods
|
| Name | Description |
|---|
.gif) | AddAttributesToRender | Adds the HTML attributes and styles of an ImageMap control to be rendered to the specified System.Web.UI..::.HtmlTextWriter. (Overrides Image..::.AddAttributesToRender(HtmlTextWriter).) | .gif) | AddedControl | Called after a child control is added to the Controls collection of the Control object. (Inherited from Control.) | .gif) | AddParsedSubObject | Notifies the server control that an element, either XML or HTML, was parsed, and adds the element to the server control's ControlCollection object. (Inherited from Control.) | .gif) | ApplyStyle | Copies any nonblank elements of the specified style to the Web control, overwriting any existing style elements of the control. This method is primarily used by control developers. (Inherited from WebControl.) | .gif) | ApplyStyleSheetSkin | Applies the style properties defined in the page style sheet to the control. (Inherited from Control.) | .gif) | BuildProfileTree | Infrastructure. Gathers information about the server control and delivers it to the Trace property to be displayed when tracing is enabled for the page. (Inherited from Control.) | .gif) | ClearCachedClientID | Infrastructure. Sets the cached ClientID value to nullNothingnullptra null reference (Nothing in Visual Basic). (Inherited from Control.) | .gif) | ClearChildControlState | Deletes the control-state information for the server control's child controls. (Inherited from Control.) | .gif) | ClearChildState | Deletes the view-state and control-state information for all the server control's child controls. (Inherited from Control.) | .gif) | ClearChildViewState | Deletes the view-state information for all the server control's child controls. (Inherited from Control.) | .gif) | ClearEffectiveClientIDMode | Infrastructure. Sets the ClientIDMode property of the current control instance and of any child controls to Inherit. (Inherited from Control.) | .gif) | CopyBaseAttributes | Copies the properties not encapsulated by the Style object from the specified Web server control to the Web server control that this method is called from. This method is used primarily by control developers. (Inherited from WebControl.) | .gif) | CreateChildControls | Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering. (Inherited from Control.) | .gif) | CreateControlCollection | Creates a new ControlCollection object to hold the child controls (both literal and server) of the server control. (Inherited from Control.) | .gif) | CreateControlStyle | Creates the style object that is used internally by the WebControl class to implement all style related properties. This method is used primarily by control developers. (Inherited from WebControl.) | .gif) | DataBind()()() | Binds a data source to the invoked server control and all its child controls. (Inherited from Control.) | .gif) | DataBind(Boolean) | Binds a data source to the invoked server control and all its child controls with an option to raise the DataBinding event. (Inherited from Control.) | .gif) | DataBindChildren | Binds a data source to the server control's child controls. (Inherited from Control.) | .gif) | Dispose | Enables a server control to perform final clean up before it is released from memory. (Inherited from Control.) | .gif) | EnsureChildControls | Determines whether the server control contains child controls. If it does not, it creates child controls. (Inherited from Control.) | .gif) | EnsureID | Creates an identifier for controls that do not have an identifier assigned. (Inherited from Control.) | .gif) | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) | .gif) | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | .gif) | FindControl(String) | Searches the current naming container for a server control with the specified id parameter. (Inherited from Control.) | .gif) | FindControl(String, Int32) | Infrastructure. Searches the current naming container for a server control with the specified id and an integer, specified in the pathOffset parameter, which aids in the search. You should not override this version of the FindControl method. (Inherited from Control.) | .gif) | Focus | Sets input focus to a control. (Inherited from Control.) | .gif) | GetDesignModeState | Infrastructure. Gets design-time data for a control. (Inherited from Control.) | .gif) | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | .gif) | GetRouteUrl(Object) | Gets the URL that corresponds to a set of route parameters. (Inherited from Control.) | .gif) | GetRouteUrl(RouteValueDictionary) | Gets the URL that corresponds to a set of route parameters. (Inherited from Control.) | .gif) | GetRouteUrl(String, Object) | Gets the URL that corresponds to a set of route parameters and a route name. (Inherited from Control.) | .gif) | GetRouteUrl(String, RouteValueDictionary) | Gets the URL that corresponds to a set of route parameters and a route name. (Inherited from Control.) | .gif) | GetType | Gets the Type of the current instance. (Inherited from Object.) | .gif) | GetUniqueIDRelativeTo | Returns the prefixed portion of the UniqueID property of the specified control. (Inherited from Control.) | .gif) | HasControls | Determines if the server control contains any child controls. (Inherited from Control.) | .gif) | HasEvents | Returns a value indicating whether events are registered for the control or any child controls. (Inherited from Control.) | .gif) | IsLiteralContent | Infrastructure. Determines if the server control holds only literal content. (Inherited from Control.) | .gif) | LoadControlState | Restores control-state information from a previous page request that was saved by the SaveControlState method. (Inherited from Control.) | .gif) | LoadViewState | Restores view-state information for the ImageMap control from a previous page request that was saved by the SaveViewState method. (Overrides WebControl..::.LoadViewState(Object).) | .gif) | MapPathSecure | Retrieves the physical path that a virtual path, either absolute or relative, maps to. (Inherited from Control.) | .gif) | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | .gif) | MergeStyle | Copies any nonblank elements of the specified style to the Web control, but will not overwrite any existing style elements of the control. This method is used primarily by control developers. (Inherited from WebControl.) | .gif) | OnBubbleEvent | Determines whether the event for the server control is passed up the page's UI server control hierarchy. (Inherited from Control.) | .gif) | OnClick | Raises the Click event for the ImageMap control. | .gif) | OnDataBinding | Raises the DataBinding event. (Inherited from Control.) | .gif) | OnInit | Raises the Init event. (Inherited from Control.) | .gif) | OnLoad | Raises the Load event. (Inherited from Control.) | .gif) | OnPreRender | Raises the PreRender event. (Inherited from Control.) | .gif) | OnUnload | Raises the Unload event. (Inherited from Control.) | .gif) | OpenFile | Gets a Stream used to read a file. (Inherited from Control.) | .gif) | RaiseBubbleEvent | Assigns any sources of the event and its information to the control's parent. (Inherited from Control.) | .gif) | RaisePostBackEvent | Raises events for the ImageMap control when a form is posted back to the server. | .gif) | RemovedControl | Called after a child control is removed from the Controls collection of the Control object. (Inherited from Control.) | .gif) | Render | Sends the ImageMap control content to the specified System.Web.UI..::.HtmlTextWriter object, which writes the content to render on the client. (Overrides WebControl..::.Render(HtmlTextWriter).) | .gif) | RenderBeginTag | Renders the HTML opening tag of the control to the specified writer. This method is used primarily by control developers. (Inherited from WebControl.) | .gif) | RenderChildren | Outputs the content of a server control's children to a provided HtmlTextWriter object, which writes the content to be rendered on the client. (Inherited from Control.) | .gif) | RenderContents | Renders the image control contents to the specified writer. (Inherited from Image.) | .gif) | RenderControl(HtmlTextWriter) | Outputs server control content to a provided HtmlTextWriter object and stores tracing information about the control if tracing is enabled. (Inherited from Control.) | .gif) | RenderControl(HtmlTextWriter, ControlAdapter) | Outputs server control content to a provided HtmlTextWriter object using a provided ControlAdapter object. (Inherited from Control.) | .gif) | RenderEndTag | Renders the HTML closing tag of the control into the specified writer. This method is used primarily by control developers. (Inherited from WebControl.) | .gif) | ResolveAdapter | Gets the control adapter responsible for rendering the specified control. (Inherited from Control.) | .gif) | ResolveClientUrl | Gets a URL that can be used by the browser. (Inherited from Control.) | .gif) | ResolveUrl | Converts a URL into one that is usable on the requesting client. (Inherited from Control.) | .gif) | SaveControlState | Saves any server control state changes that have occurred since the time the page was posted back to the server. (Inherited from Control.) | .gif) | SaveViewState | Saves any changes to an ImageMap control's view-state that have occurred since the time the page was posted back to the server. (Overrides WebControl..::.SaveViewState()()().) | .gif) | SetDesignModeState | Sets design-time data for a control. (Inherited from Control.) | .gif) | SetRenderMethodDelegate | Infrastructure. Assigns an event handler delegate to render the server control and its content into its parent control. (Inherited from Control.) | .gif) | ToString | Returns a string that represents the current object. (Inherited from Object.) | .gif) | TrackViewState | Tracks view-state changes to the ImageMap control so they can be stored in the control's StateBag object. This object is accessible through the Control..::.ViewState property. (Overrides WebControl..::.TrackViewState()()().) | Top

Extension Methods

Explicit Interface Implementations
|
| Name | Description |
|---|
.gif) .gif) | IAttributeAccessor..::.GetAttribute | Infrastructure. Gets an attribute of the Web control with the specified name. (Inherited from WebControl.) | .gif) .gif) | IAttributeAccessor..::.SetAttribute | Sets an attribute of the Web control to the specified name and value. (Inherited from WebControl.) | .gif) .gif) | IControlBuilderAccessor..::.ControlBuilder | For a description of this member, see IControlBuilderAccessor..::.ControlBuilder. (Inherited from Control.) | .gif) .gif) | IControlDesignerAccessor..::.GetDesignModeState | For a description of this member, see IControlDesignerAccessor..::.GetDesignModeState. (Inherited from Control.) | .gif) .gif) | IControlDesignerAccessor..::.SetDesignModeState | For a description of this member, see IControlDesignerAccessor..::.SetDesignModeState. (Inherited from Control.) | .gif) .gif) | IControlDesignerAccessor..::.SetOwnerControl | Infrastructure. For a description of this member, see IControlDesignerAccessor..::.SetOwnerControl. (Inherited from Control.) | .gif) .gif) | IControlDesignerAccessor..::.UserData | For a description of this member, see IControlDesignerAccessor..::.UserData. (Inherited from Control.) | .gif) .gif) | IDataBindingsAccessor..::.DataBindings | For a description of this member, see IDataBindingsAccessor..::.DataBindings. (Inherited from Control.) | .gif) .gif) | IDataBindingsAccessor..::.HasDataBindings | For a description of this member, see IDataBindingsAccessor..::.HasDataBindings. (Inherited from Control.) | .gif) .gif) | IExpressionsAccessor..::.Expressions | For a description of this member, see IExpressionsAccessor..::.Expressions. (Inherited from Control.) | .gif) .gif) | IExpressionsAccessor..::.HasExpressions | For a description of this member, see IExpressionsAccessor..::.HasExpressions. (Inherited from Control.) | .gif) .gif) | IParserAccessor..::.AddParsedSubObject | For a description of this member, see IParserAccessor..::.AddParsedSubObject. (Inherited from Control.) | .gif) .gif) | IPostBackEventHandler..::.RaisePostBackEvent | For a description of this member, see RaisePostBackEvent. | Top

Remarks
In this topic: IntroductionUse the 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 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 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 ImageUrl property to specify the path to the image to display for the ImageMap control. You can define any number of HotSpot objects within an ImageMap control. You can use the CircleHotSpot, RectangleHotSpot, and PolygonHotSpot classes to define hot spot regions. Alternatively, you can derive from the abstract HotSpot class to define your own custom hot spot object. There are two ways to specify the behavior of a HotSpot object in an ImageMap control when the HotSpot is clicked. You can use either the HotSpotMode property on the ImageMap control or the HotSpotMode property on an individual HotSpot object. These properties are set using one of the HotSpotMode enumeration values. If both properties are set, the HotSpotMode property specified on each individual HotSpot object takes precedence over the HotSpotMode property on the ImageMap control. To navigate to a URL, set either the ImageMap..::.HotSpotMode property or the HotSpot..::.HotSpotMode property to HotSpotMode.Navigate. Use the 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 PostBackValue property to specify a name for the hot spot region. This name will be passed in the ImageMapEventArgs event data when a postback event occurs. When a postback HotSpot is clicked, the Click event is raised. To programmatically control the actions performed when a postback HotSpot is clicked, provide an event handler for the Click event. To cause all HotSpot objects in an 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 HotSpot object to HotSpotMode.NotSet or do not specify a value for the HotSpot..::.HotSpotMode property. To specify different behaviors for HotSpot objects in an ImageMap, set the HotSpot..::.HotSpotMode property on each individual HotSpot object to either HotSpotMode.Navigate or HotSpotMode.PostBack. AccessibilityDeclarative Syntax
<asp:ImageMap
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"
CssClass="string"
DescriptionUrl="uri"
Enabled="True|False"
EnableTheming="True|False"
EnableViewState="True|False"
ForeColor="color name|#dddddd"
Height="size"
HotSpotMode="NotSet|Navigate|PostBack|Inactive"
ID="string"
ImageAlign="NotSet|Left|Right|Baseline|Top|Middle|Bottom|
AbsBottom|AbsMiddle|TextTop"
ImageUrl="uri"
OnClick="Click 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"
runat="server"
SkinID="string"
Style="string"
TabIndex="integer"
Target="string"
ToolTip="string"
Visible="True|False"
Width="size"
>
<asp:CircleHotSpot
AccessKey="string"
AlternateText="string"
HotSpotMode="NotSet|Navigate|PostBack|Inactive"
NavigateUrl="uri"
PostBackValue="string"
Radius="integer"
TabIndex="integer"
Target="string|_blank|_parent|_search|_self|_top"
X="integer"
Y="integer"
/>
<asp:PolygonHotSpot
AccessKey="string"
AlternateText="string"
Coordinates="string"
HotSpotMode="NotSet|Navigate|PostBack|Inactive"
NavigateUrl="uri"
PostBackValue="string"
TabIndex="integer"
Target="string|_blank|_parent|_search|_self|_top"
/>
<asp:RectangleHotSpot
AccessKey="string"
AlternateText="string"
Bottom="integer"
HotSpotMode="NotSet|Navigate|PostBack|Inactive"
Left="integer"
NavigateUrl="uri"
PostBackValue="string"
Right="integer"
TabIndex="integer"
Target="string|_blank|_parent|_search|_self|_top"
Top="integer"
/>
</asp:ImageMap>

Examples
The following code example demonstrates how to declaratively create an ImageMap control that contains two CircleHotSpot objects. The HotSpot..::.HotSpotMode property is set to HotSpotMode.Navigate, which causes the page to navigate to the specified URL each time a user clicks one of the circle hot spot regions. For this example to work correctly, you must supply your own image for the ImageUrl property and update the path to the image appropriately so that the application can locate it.
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head id="head1" runat="server">
<title>ImageMap Class Navigate Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>ImageMap Class Navigate Example</h3>
<h4>Shopping Choices:</h4>
<asp:imagemap id="Shop"
imageurl="Images/ShopChoice.jpg"
alternatetext="Shopping choices"
runat="Server">
<asp:circlehotspot
navigateurl="http://www.tailspintoys.com"
x="145"
y="120"
radius="75"
hotspotmode="Navigate"
alternatetext="Shop for toys">
</asp:circlehotspot>
<asp:circlehotspot
navigateurl="http://www.cohowinery.com"
x="145"
y="290"
radius="75"
hotspotmode="Navigate"
alternatetext="Shop for wine">
</asp:circlehotspot>
</asp:imagemap>
</form>
</body>
</html>
<%@ page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head id="head1" runat="server">
<title>ImageMap Class Navigate Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>ImageMap Class Navigate Example</h3>
<h4>Shopping Choices:</h4>
<asp:imagemap id="Shop"
imageurl="Images/ShopChoice.jpg"
width="150"
height="360"
alternatetext="Shopping choices"
runat="Server">
<asp:circlehotspot
navigateurl="http://www.tailspintoys.com"
x="75"
y="290"
radius="75"
hotspotmode="Navigate"
alternatetext="Shop for toys">
</asp:circlehotspot>
<asp:circlehotspot
navigateurl="http://www.cohowinery.com"
x="75"
y="120"
radius="75"
hotspotmode="Navigate"
alternatetext="Shop for wine">
</asp:circlehotspot>
</asp:imagemap>
</form>
</body>
</html>
The following code example demonstrates how to declaratively create an ImageMap control that contains two RectangleHotSpot objects. The ImageMap..::.HotSpotMode property is set to HotSpotMode.PostBack, which causes the page to post back to the server each time a user clicks one of the hot spot regions. For this example to work correctly, you must supply your own image for the ImageUrl property and update the path to the image appropriately so that the application can locate it.
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub VoteMap_Clicked(ByVal sender As Object, ByVal e As ImageMapEventArgs)
Dim coordinates As String
Dim hotSpotType As String
Dim yescount As Integer
Dim nocount As Integer
If (ViewState("yescount") IsNot Nothing) Then
yescount = Convert.ToInt32(ViewState("yescount"))
Else
yescount = 0
End If
If (ViewState("nocount") IsNot Nothing) Then
nocount = Convert.ToInt32(ViewState("nocount"))
Else
nocount = 0
End If
' When a user clicks the "Yes" hot spot,
' display the hot spot's name and coordinates.
If (e.PostBackValue.Contains("Yes")) Then
yescount += 1
coordinates = Vote.HotSpots(0).GetCoordinates()
hotSpotType = Vote.HotSpots(0).ToString()
Message1.Text = "You selected " & hotSpotType & " " & e.PostBackValue & ".<br />" & _
"The coordinates are " & coordinates & ".<br />" & _
"The current vote count is " & yescount.ToString() & _
" yes votes and " & nocount.ToString() & " no votes."
' When a user clicks the "No" hot spot,
' display the hot spot's name and coordinates.
ElseIf (e.PostBackValue.Contains("No")) Then
nocount += 1
coordinates = Vote.HotSpots.Item(1).GetCoordinates()
hotSpotType = Vote.HotSpots.Item(1).ToString()
Message1.Text = "You selected " & hotSpotType & " " & e.PostBackValue & ".<br />" & _
"The coordinates are " & coordinates & ".<br />" & _
"The current vote count is " & yescount.ToString() & _
" yes votes and " & nocount.ToString() & " no votes."
Else
Message1.Text = "You did not click a valid hot spot region."
End If
ViewState("yescount") = yescount
ViewState("nocount") = nocount
End Sub
</script>
<html >
<head id="head1" runat="server">
<title>ImageMap Class Post Back Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>ImageMap Class Post Back Example</h3>
<asp:imagemap id="Vote"
imageurl="Images/VoteImage.jpg"
width="400"
height="200"
alternatetext="Vote Yes or No"
hotspotmode="PostBack"
onclick="VoteMap_Clicked"
runat="Server">
<asp:RectangleHotSpot
top="0"
left="0"
bottom="200"
right="200"
postbackvalue="Yes"
alternatetext="Vote yes">
</asp:RectangleHotSpot>
<asp:RectangleHotSpot
top="0"
left="201"
bottom="200"
right="400"
postbackvalue="No"
alternatetext="Vote no">
</asp:RectangleHotSpot>
</asp:imagemap>
<br /><br />
<asp:label id="Message1"
runat="Server">
</asp:label>
</form>
</body>
</html>
<%@ page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void VoteMap_Clicked (Object sender, ImageMapEventArgs e)
{
string coordinates;
string hotSpotType;
int yescount = ((ViewState["yescount"] != null)? (int)ViewState["yescount"] : 0);
int nocount = ((ViewState["nocount"] != null)? (int)ViewState["nocount"] : 0);
// When a user clicks the "Yes" hot spot,
// display the hot spot's name and coordinates.
if (e.PostBackValue.Contains("Yes"))
{
yescount += 1;
coordinates = Vote.HotSpots[0].GetCoordinates();
hotSpotType = Vote.HotSpots[0].ToString ();
Message1.Text = "You selected " + hotSpotType + " " + e.PostBackValue + ".<br />" +
"The coordinates are " + coordinates + ".<br />" +
"The current vote count is " + yescount.ToString() +
" yes votes and " + nocount.ToString() + " no votes.";
}
// When a user clicks the "No" hot spot,
// display the hot spot's name and coordinates.
else if (e.PostBackValue.Contains("No"))
{
nocount += 1;
coordinates = Vote.HotSpots[1].GetCoordinates();
hotSpotType = Vote.HotSpots[1].ToString ();
Message1.Text = "You selected " + hotSpotType + " " + e.PostBackValue + ".<br />" +
"The coordinates are " + coordinates + ".<br />" +
"The current vote count is " + yescount.ToString() +
" yes votes and " + nocount.ToString() + " no votes.";
}
else
{
Message1.Text = "You did not click a valid hot spot region.";
}
ViewState["yescount"] = yescount;
ViewState["nocount"] = nocount;
}
</script>
<html >
<head id="head1" runat="server">
<title>ImageMap Class Post Back Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>ImageMap Class Post Back Example</h3>
<asp:imagemap id="Vote"
imageurl="Images/VoteImage.jpg"
width="400"
height="200"
alternatetext="Vote Yes or No"
hotspotmode="PostBack"
onclick="VoteMap_Clicked"
runat="Server">
<asp:RectangleHotSpot
top="0"
left="0"
bottom="200"
right="200"
postbackvalue="Yes"
alternatetext="Vote yes">
</asp:RectangleHotSpot>
<asp:RectangleHotSpot
top="0"
left="201"
bottom="200"
right="400"
postbackvalue="No"
alternatetext="Vote no">
</asp:RectangleHotSpot>
</asp:imagemap>
<br /><br />
<asp:label id="Message1"
runat="Server">
</asp:label>
</form>
</body>
</html>
The following code example demonstrates how to create an ImageMap control that contains hot spots with different behaviors. The background area is a defined as a single RectangleHotSpot that posts back to the server. Three RectangleHotSpot objects are defined in the same region. Each of these hot spots looks like a button and navigates to a URL. When an ImageMap control is clicked in a region where two hot spots overlap, the hot spot that is declared first has precedence. In this example, the button hot spots are declared first and the background hot spot that contains them is declared last. Therefore, the user gets the behavior of the button RectangleHotSpot object, not the background RectangleHotSpot object, when the user clicks a button hot spot. For this example to work correctly, you must supply your own image for the ImageUrl property and update the path to the image appropriately so that the application can locate it.
<%@ page language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub ButtonsMap_Clicked(ByVal sender As Object, ByVal e As ImageMapEventArgs)
' When a user clicks the "Background" hot spot,
' display the hot spot's value.
If (e.PostBackValue = "Background") Then
Dim coordinates As String
coordinates = Buttons.HotSpots(3).GetCoordinates()
Message1.Text = "You selected the " & e.PostBackValue & "<br />" & _
"The coordinates are " & coordinates
End If
End Sub
</script>
<html >
<head id="head1" runat="server">
<title>ImageMap Class Mixed HotSpotMode Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>ImageMap Class Mixed HotSpotMode Example</h3>
<!--In this scenario, the ImageMap.HotSpotMode
property is not set, because the
HotSpotMode property is set on each individual
RectangleHotSpot object to specify its behavior.-->
<asp:imagemap id="Buttons"
imageurl="Images/MixedImage.jpg"
width="350"
height="350"
alternatetext="Navigation buttons"
hotspotmode="NotSet"
onclick="ButtonsMap_Clicked"
runat="Server">
<asp:RectangleHotSpot
hotspotmode="Navigate"
NavigateUrl="http://www.contoso.com"
alternatetext="Button 1"
top="50"
left="50"
bottom="100"
right="300">
</asp:RectangleHotSpot>
<asp:RectangleHotSpot
hotspotmode="Navigate"
NavigateUrl="http://www.tailspintoys.com"
alternatetext="Button 2"
top="150"
left="50"
bottom="200"
right="300">
</asp:RectangleHotSpot>
<asp:RectangleHotSpot
hotspotmode="Navigate"
NavigateUrl="http://www.cohowinery.com"
alternatetext="Button 3"
top="250"
left="50"
bottom="300"
right="300">
</asp:RectangleHotSpot>
<asp:RectangleHotSpot
hotspotmode="PostBack"
PostBackValue="Background"
alternatetext="Background"
top="0"
left="0"
bottom="350"
right="350">
</asp:RectangleHotSpot>
</asp:imagemap>
<br />
<asp:label id="Message1"
runat="Server">
</asp:label>
</form>
</body>
</html>
<%@ page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void ButtonsMap_Clicked(object sender, ImageMapEventArgs e)
{
// When a user clicks the "Background" hot spot,
// display the hot spot's value.
if (e.PostBackValue == "Background")
{
string coordinates = Buttons.HotSpots[3].GetCoordinates();
Message1.Text = "You selected the " + e.PostBackValue + "<br />" +
"The coordinates are " + coordinates;
}
}
</script>
<html >
<head id="head1" runat="server">
<title>ImageMap Class Mixed HotSpotMode Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>ImageMap Class Mixed HotSpotMode Example</h3>
<!--In this scenario, the ImageMap.HotSpotMode
property is not set, because the
HotSpotMode property is set on each individual
RectangleHotSpot object to specify its behavior.-->
<asp:imagemap id="Buttons"
imageurl="Images/MixedImage.jpg"
width="350"
height="350"
alternatetext="Navigation buttons"
hotspotmode="NotSet"
onclick="ButtonsMap_Clicked"
runat="Server">
<asp:RectangleHotSpot
hotspotmode="Navigate"
NavigateUrl="http://www.contoso.com"
alternatetext="Button 1"
top="50"
left="50"
bottom="100"
right="300">
</asp:RectangleHotSpot>
<asp:RectangleHotSpot
hotspotmode="Navigate"
NavigateUrl="http://www.tailspintoys.com"
alternatetext="Button 2"
top="150"
left="50"
bottom="200"
right="300">
</asp:RectangleHotSpot>
<asp:RectangleHotSpot
hotspotmode="Navigate"
NavigateUrl="http://www.cohowinery.com"
alternatetext="Button 3"
top="250"
left="50"
bottom="300"
right="300">
</asp:RectangleHotSpot>
<asp:RectangleHotSpot
hotspotmode="PostBack"
PostBackValue="Background"
alternatetext="Background"
top="0"
left="0"
bottom="350"
right="350">
</asp:RectangleHotSpot>
</asp:imagemap>
<br />
<asp:label id="Message1"
runat="Server">
</asp:label>
</form>
</body>
</html>

Version Information
.NET FrameworkSupported in: 4, 3.5, 3.0, 2.0

Platforms
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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

See Also
|
Bibliothèque de classes .NET Framework ImageMap, classe Crée un contrôle qui affiche une image sur une page. Lorsqu'un clic est effectué sur une zone réactive définie dans le contrôle ImageMap, le contrôle génère une publication (postback) sur le serveur ou atteint une URL spécifiée.

Hiérarchie d'héritage
Espace de noms :
System.Web.UI.WebControls
Assembly :
System.Web (dans System.Web.dll)

Syntaxe
Public Class ImageMap _
Inherits Image _
Implements IPostBackEventHandler
public class ImageMap : Image, IPostBackEventHandler
public ref class ImageMap : public Image,
IPostBackEventHandler
type ImageMap =
class
inherit Image
interface IPostBackEventHandler
end
Le type ImageMap expose les membres suivants.

Constructeurs
|
| Nom | Description |
|---|
.gif) | ImageMap | Initialise une nouvelle instance de la classe ImageMap. | Début

Méthodes
|
| Nom | Description |
|---|
.gif) | AddAttributesToRender | Ajoute les attributs et les styles HTML d'un contrôle ImageMap à rendre au System.Web.UI..::.HtmlTextWriter spécifié. (Substitue Image..::.AddAttributesToRender(HtmlTextWriter).) | .gif) | AddedControl | Appelée après l'ajout d'un contrôle enfant à la collection Controls de l'objet Control. (Hérité de Control.) | .gif) | AddParsedSubObject | Avertit le contrôle serveur qu'un élément XML ou HTML a été analysé et l'ajoute à l'objet ControlCollection du contrôle serveur. (Hérité de Control.) | .gif) | ApplyStyle | Copie tous les éléments non vides du style spécifié vers le contrôle Web, en remplaçant les éléments de style existants du contrôle. Cette méthode est principalement utilisée par des développeurs de contrôles. (Hérité de WebControl.) | .gif) | ApplyStyleSheetSkin | Applique les propriétés de style définies dans la feuille de style de la page au contrôle. (Hérité de Control.) | .gif) | BuildProfileTree | Infrastructure. Collecte des informations sur le contrôle serveur et les livre à la propriété Trace à afficher lorsque le traçage est activé pour la page. (Hérité de Control.) | .gif) | ClearCachedClientID | Infrastructure. Affecte à la valeur ClientID mise en cache la valeur nullNothingnullptrune référence null (Nothing en Visual Basic). (Hérité de Control.) | .gif) | ClearChildControlState | Supprime les informations sur l'état du contrôle des contrôles enfants du contrôle serveur. (Hérité de Control.) | .gif) | ClearChildState | Supprime les informations sur l'état d'affichage et sur l'état du contrôle de tous les contrôles enfants du contrôle serveur. (Hérité de Control.) | .gif) | ClearChildViewState | Supprime les informations d'état d'affichage de tous les contrôles enfants du contrôle serveur. (Hérité de Control.) | .gif) | ClearEffectiveClientIDMode | Infrastructure. Affecte la valeur Inherit à la propriété ClientIDMode de l'instance de contrôle actuelle et de tous contrôles enfants. (Hérité de Control.) | .gif) | CopyBaseAttributes | Copie les propriétés non encapsulées par l'objet Style du contrôle serveur Web spécifié vers le contrôle serveur Web à partir duquel cette méthode est appelée. Cette méthode est principalement utilisée par des développeurs de contrôles. (Hérité de WebControl.) | .gif) | CreateChildControls | Appelé par l'infrastructure de page ASP.NET pour avertir les contrôles serveur qui utilisent une implémentation basée sur la composition qu'ils doivent créer tous les contrôles enfants qu'ils contiennent en préparation de la publication ou du rendu. (Hérité de Control.) | .gif) | CreateControlCollection | Crée un nouvel objet ControlCollection pour contenir les contrôles enfants (littéraux et serveur) du contrôle serveur. (Hérité de Control.) | .gif) | CreateControlStyle | Crée l'objet de style qui est utilisé de manière interne par la classe WebControl pour implémenter toutes les propriétés associées au style. Cette méthode est principalement utilisée par des développeurs de contrôles. (Hérité de WebControl.) | .gif) | DataBind()()() | Lie une source de données au contrôle serveur appelé et à tous ses contrôles enfants. (Hérité de Control.) | .gif) | DataBind(Boolean) | Lie une source de données au contrôle serveur appelé et tous ses contrôles enfants avec une option pour déclencher l'événement DataBinding. (Hérité de Control.) | .gif) | DataBindChildren | Lie une source de données aux contrôles enfants du contrôle serveur. (Hérité de Control.) | .gif) | Dispose | Permet à un contrôle serveur d'effectuer le nettoyage final avant qu'il soit libéré de la mémoire. (Hérité de Control.) | .gif) | EnsureChildControls | Détermine si le contrôle serveur contient des contrôles enfants. S'il ne contient pas de contrôles enfants, il en crée. (Hérité de Control.) | .gif) | EnsureID | Crée un identificateur pour les contrôles auxquels aucun identificateur n'est assigné. (Hérité de Control.) | .gif) | Equals(Object) | Détermine si l'Object spécifié est égal à l'Object en cours. (Hérité de Object.) | .gif) | Finalize | Autorise un objet à tenter de libérer des ressources et d'exécuter d'autres opérations de netto***ge avant qu'il ne soit récupéré par l'opération garbage collection. (Hérité de Object.) | .gif) | FindControl(String) | Recherche un contrôle serveur possédant le paramètre id spécifié dans le conteneur d'attribution de noms actuel. (Hérité de Control.) | .gif) | FindControl(String, Int32) | Infrastructure. Recherche le conteneur d'attribution de noms actuel d'un contrôle serveur avec l'id spécifié et un entier, spécifié dans le paramètre pathOffset, qui facilite la recherche. Vous ne devez pas substituer cette version de la méthode FindControl. (Hérité de Control.) | .gif) | Focus | Affecte le focus d'entrée à un contrôle. (Hérité de Control.) | .gif) | GetDesignModeState | Infrastructure. Obtient les données au moment du design pour un contrôle. (Hérité de Control.) | .gif) | GetHashCode | Sert de fonction de hachage pour un type particulier. (Hérité de Object.) | .gif) | GetRouteUrl(Object) | Obtient l'URL qui correspond à un jeu de paramètres d'itinéraire. (Hérité de Control.) | .gif) | GetRouteUrl(RouteValueDictionary) | Obtient l'URL qui correspond à un jeu de paramètres d'itinéraire. (Hérité de Control.) | .gif) | GetRouteUrl(String, Object) | Obtient l'URL qui correspond à un jeu de paramètres d'itinéraire et à un nom d'itinéraire. (Hérité de Control.) | .gif) | GetRouteUrl(String, RouteValueDictionary) | Obtient l'URL qui correspond à un jeu de paramètres d'itinéraire et à un nom d'itinéraire. (Hérité de Control.) | .gif) | GetType | Obtient le Type de l'instance actuelle. (Hérité de Object.) | .gif) | GetUniqueIDRelativeTo | Retourne la partie préfixée de la propriété UniqueID du contrôle spécifié. (Hérité de Control.) | .gif) | HasControls | Détermine si le contrôle serveur contient des contrôles enfants. (Hérité de Control.) | .gif) | HasEvents | Retourne une valeur indiquant si des événements sont inscrits pour le contrôle ou des contrôles enfants. (Hérité de Control.) | .gif) | IsLiteralContent | Infrastructure. Détermine si le contrôle serveur ne détient qu'un contenu littéral. (Hérité de Control.) | .gif) | LoadControlState | Restaure des informations sur l'état du contrôle à partir d'une demande de page antérieure enregistrée par la méthode SaveControlState. (Hérité de Control.) | .gif) | LoadViewState | Restaure les informations d'état d'affichage du contrôle ImageMap à partir d'une demande de page antérieure enregistrée par la méthode SaveViewState. (Substitue WebControl..::.LoadViewState(Object).) | .gif) | MapPathSecure | Récupère le chemin d'accès physique auquel un chemin d'accès virtuel, absolu ou relatif, correspond. (Hérité de Control.) | .gif) | MemberwiseClone | Crée une copie superficielle de l'objet Object actif. (Hérité de Object.) | .gif) | MergeStyle | Copie tous les éléments non vides du style spécifié vers le contrôle Web, mais ne remplace aucun élément de style existant du contrôle. Cette méthode est principalement utilisée par des développeurs de contrôles. (Hérité de WebControl.) | .gif) | OnBubbleEvent | Détermine si l'événement pour le contrôle serveur est passé dans la hiérarchie des contrôles serveur de l'interface utilisateur de la page. (Hérité de Control.) | .gif) | OnClick | Déclenche l'événement Click pour le contrôle ImageMap. | .gif) | OnDataBinding | Déclenche l'événement DataBinding. (Hérité de Control.) | .gif) | OnInit | Déclenche l'événement Init. (Hérité de Control.) | .gif) | OnLoad | Déclenche l'événement Load. (Hérité de Control.) | .gif) | OnPreRender | Déclenche l'événement PreRender. (Hérité de Control.) | .gif) | OnUnload | Déclenche l'événement Unload. (Hérité de Control.) | .gif) | OpenFile | Obtient un Stream utilisé pour lire un fichier. (Hérité de Control.) | .gif) | RaiseBubbleEvent | Assigne les sources éventuelles de l'événement et ses informations au parent du contrôle. (Hérité de Control.) | .gif) | RaisePostBackEvent | Déclenche les événements du contrôle ImageMap lorsqu'un formulaire est publié sur le serveur. | .gif) | RemovedControl | Appelée après la suppression d'un contrôle enfant dans la collection Controls de l'objet Control. (Hérité de Control.) | .gif) | Render | Envoie le contenu du contrôle ImageMap à un objet System.Web.UI..::.HtmlTextWriter spécifié, qui écrit le contenu à rendre sur le client. (Substitue WebControl..::.Render(HtmlTextWriter).) | .gif) | RenderBeginTag | Génère le rendu de la balise d'ouverture HTML du contrôle via le writer spécifié. Cette méthode est principalement utilisée par des développeurs de contrôles. (Hérité de WebControl.) | .gif) | RenderChildren | Renvoie le contenu des enfants d'un contrôle serveur dans un objet HtmlTextWriter fourni, qui écrit le contenu à rendre sur le client. (Hérité de Control.) | .gif) | RenderContents | Génère le rendu du contrôle d'image via le writer spécifié. (Hérité de Image.) | .gif) | RenderControl(HtmlTextWriter) | Renvoie le contenu du contrôle serveur dans un objet HtmlTextWriter fourni et stocke des informations de traçage au sujet du contrôle si le traçage est activé. (Hérité de Control.) | .gif) | RenderControl(HtmlTextWriter, ControlAdapter) | Génère le contenu du contrôle serveur dans un objet HtmlTextWriter à l'aide d'un objet ControlAdapter fourni. (Hérité de Control.) | .gif) | RenderEndTag | Génère le rendu de la balise de fermeture HTML du contrôle via le writer spécifié. Cette méthode est principalement utilisée par des développeurs de contrôles. (Hérité de WebControl.) | .gif) | ResolveAdapter | Obtient l'adaptateur de contrôles responsable du rendu du contrôle spécifié. (Hérité de Control.) | .gif) | ResolveClientUrl | Obtient une URL qui peut être utilisée par le navigateur. (Hérité de Control.) | .gif) | ResolveUrl | Convertit une URL en une URL que le client soit en mesure d'utiliser. (Hérité de Control.) | .gif) | SaveControlState | Enregistre les modifications éventuellement apportées à l'état du contrôle serveur depuis la publication de la page sur le serveur. (Hérité de Control.) | .gif) | SaveViewState | Enregistre les modifications éventuellement apportées à l'état d'affichage du contrôle ImageMap depuis la publication de la page sur le serveur. (Substitue WebControl..::.SaveViewState()()().) | .gif) | SetDesignModeState | Définit les données au moment du design pour un contrôle. (Hérité de Control.) | .gif) | SetRenderMethodDelegate | Infrastructure. Assigne un délégué de gestionnaires d'événements pour générer le rendu du contrôle serveur et de son contenu dans son contrôle parent. (Hérité de Control.) | .gif) | ToString | Retourne une chaîne qui représente l'objet actuel. (Hérité de Object.) | .gif) | TrackViewState | Suit les modifications d'état d'affichage du contrôle ImageMap afin qu'elles puissent être stockées dans l'objet StateBag du contrôle. Cet objet est accessible via la propriété Control..::.ViewState. (Substitue WebControl..::.TrackViewState()()().) | Début

Méthodes d'extension

Implémentations d'interface explicite
|
| Nom | Description |
|---|
.gif) .gif) | IAttributeAccessor..::.GetAttribute | Infrastructure. Obtient un attribut du contrôle Web avec le nom spécifié. (Hérité de WebControl.) | .gif) .gif) | IAttributeAccessor..::.SetAttribute | Affecte au nom et à la valeur spécifiés un attribut du contrôle Web. (Hérité de WebControl.) | .gif) .gif) | IControlBuilderAccessor..::.ControlBuilder | Pour obtenir une description de ce membre, consultez IControlBuilderAccessor..::.ControlBuilder. (Hérité de Control.) | .gif) .gif) | IControlDesignerAccessor..::.GetDesignModeState | Pour obtenir une description de ce membre, consultez IControlDesignerAccessor..::.GetDesignModeState. (Hérité de Control.) | .gif) .gif) | IControlDesignerAccessor..::.SetDesignModeState | Pour obtenir une description de ce membre, consultez IControlDesignerAccessor..::.SetDesignModeState. (Hérité de Control.) | .gif) .gif) | IControlDesignerAccessor..::.SetOwnerControl | Infrastructure. Pour obtenir une description de ce membre, consultez IControlDesignerAccessor..::.SetOwnerControl. (Hérité de Control.) | .gif) .gif) | IControlDesignerAccessor..::.UserData | Pour obtenir une description de ce membre, consultez IControlDesignerAccessor..::.UserData. (Hérité de Control.) | .gif) .gif) | IDataBindingsAccessor..::.DataBindings | Pour obtenir une description de ce membre, consultez IDataBindingsAccessor..::.DataBindings. (Hérité de Control.) | .gif) .gif) | IDataBindingsAccessor..::.HasDataBindings | Pour obtenir une description de ce membre, consultez IDataBindingsAccessor..::.HasDataBindings. (Hérité de Control.) | .gif) .gif) | IExpressionsAccessor..::.Expressions | Pour obtenir une description de ce membre, consultez IExpressionsAccessor..::.Expressions. (Hérité de Control.) | .gif) .gif) | IExpressionsAccessor..::.HasExpressions | Pour obtenir une description de ce membre, consultez IExpressionsAccessor..::.HasExpressions. (Hérité de Control.) | .gif) .gif) | IParserAccessor..::.AddParsedSubObject | Pour obtenir une description de ce membre, consultez IParserAccessor..::.AddParsedSubObject. (Hérité de Control.) | .gif) .gif) | IPostBackEventHandler..::.RaisePostBackEvent | Pour obtenir une description de ce membre, consultez RaisePostBackEvent. | Début

Notes
Dans cette rubrique : IntroductionUtilisez le contrôle ImageMap pour créer une image qui contient des zones réactives définies. Lorsqu'un utilisateur clique sur une zone réactive, le contrôle peut générer une publication sur le serveur ou atteindre une URL spécifiée. Par exemple, vous pouvez utiliser ce contrôle pour afficher le plan d'une région géographique. Lorsqu'un utilisateur clique sur une région spécifique du plan, le contrôle atteint une URL qui fournit des données supplémentaires à propos de la région sélectionnée. Vous pouvez également utiliser ce contrôle pour générer une publication (postback) sur le serveur et exécuter un code spécifique en fonction de la zone réactive sur laquelle le clic a été effectué. Par exemple, vous pouvez utiliser un contrôle ImageMap pour capturer les réponses de l'utilisateur telles que les votes. Lorsqu'un utilisateur clique sur la zone réactive définie pour les votes affirmatifs, le code est appelé pour enregistrer une réponse affirmative dans une base de données. Lorsqu'un utilisateur clique sur la zone réactive définie pour les votes négatifs, une réponse négative est enregistrée. Vous pouvez également combiner ces deux scénarios dans un seul contrôle ImageMap. Par exemple, vous pouvez spécifier une zone réactive de manière à ce qu'elle atteigne une URL et une autre zone réactive de manière à ce qu'elle génère une publication (postback) sur le serveur. Utilisez la propriété ImageUrl pour spécifier le chemin d'accès à l'image à afficher pour le contrôle ImageMap. Vous pouvez définir n'importe quel nombre d'objets HotSpot dans un contrôle ImageMap. Vous pouvez utiliser les classes CircleHotSpot, RectangleHotSpot et PolygonHotSpot pour définir des zones réactives. Par ailleurs, vous pouvez dériver de la classe HotSpot abstraite pour définir votre objet de zone réactive personnalisé. Il existe deux manières de spécifier le comportement d'un objet HotSpot d'un contrôle ImageMap lorsqu'un clic est effectué sur HotSpot. Vous pouvez utiliser la propriété HotSpotMode du contrôle ImageMap ou la propriété HotSpotMode d'un objet HotSpot individuel. Ces propriétés sont définies avec l'une des valeurs d'énumération HotSpotMode. Si les deux propriétés sont définies, la propriété HotSpotMode spécifiée de chaque objet HotSpot individuel est prioritaire sur la propriété HotSpotMode du contrôle ImageMap. Pour atteindre une URL, affectez HotSpotMode.Navigate à la propriété ImageMap..::.HotSpotMode ou à la propriété HotSpot..::.HotSpotMode. Utilisez la propriété NavigateUrl pour spécifier l'URL à atteindre. Pour générer une publication (postback) sur le serveur, affectez HotSpotMode.Postback à la propriété ImageMap..::.HotSpotMode ou à la propriété HotSpot..::.HotSpotMode. Utilisez la propriété PostBackValue pour spécifier un nom pour la zone réactive. Ce nom est passé dans les données d'événement ImageMapEventArgs lorsqu'un événement de publication (postback) se produit. En cas de clic sur un HotSpot de publication, l'événement Click est déclenché. Pour contrôler par programme les actions effectuées lorsqu'un clic a été effectué sur un HotSpot de publication, fournissez un gestionnaire d'événements pour l'événement Click. Pour que tous les objets HotSpot d'un contrôle ImageMap aient le même comportement, utilisez la propriété ImageMap..::.HotSpotMode pour spécifier le comportement. Affectez ensuite HotSpotMode.NotSet à la propriété HotSpot..::.HotSpotMode de chaque objet HotSpot individuel ou ne spécifiez pas de valeur pour la propriété HotSpot..::.HotSpotMode. Pour spécifier des comportements différents pour les objets HotSpot de ImageMap, affectez HotSpotMode.Navigate ou HotSpotMode.PostBack à la propriété HotSpot..::.HotSpotMode de chaque objet HotSpot individuel. AccessibilitéSyntaxe déclarative
<asp:ImageMap
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"
CssClass="string"
DescriptionUrl="uri"
Enabled="True|False"
EnableTheming="True|False"
EnableViewState="True|False"
ForeColor="color name|#dddddd"
Height="size"
HotSpotMode="NotSet|Navigate|PostBack|Inactive"
ID="string"
ImageAlign="NotSet|Left|Right|Baseline|Top|Middle|Bottom|
AbsBottom|AbsMiddle|TextTop"
ImageUrl="uri"
OnClick="Click 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"
runat="server"
SkinID="string"
Style="string"
TabIndex="integer"
Target="string"
ToolTip="string"
Visible="True|False"
Width="size"
>
<asp:CircleHotSpot
AccessKey="string"
AlternateText="string"
HotSpotMode="NotSet|Navigate|PostBack|Inactive"
NavigateUrl="uri"
PostBackValue="string"
Radius="integer"
TabIndex="integer"
Target="string|_blank|_parent|_search|_self|_top"
X="integer"
Y="integer"
/>
<asp:PolygonHotSpot
AccessKey="string"
AlternateText="string"
Coordinates="string"
HotSpotMode="NotSet|Navigate|PostBack|Inactive"
NavigateUrl="uri"
PostBackValue="string"
TabIndex="integer"
Target="string|_blank|_parent|_search|_self|_top"
/>
<asp:RectangleHotSpot
AccessKey="string"
AlternateText="string"
Bottom="integer"
HotSpotMode="NotSet|Navigate|PostBack|Inactive"
Left="integer"
NavigateUrl="uri"
PostBackValue="string"
Right="integer"
TabIndex="integer"
Target="string|_blank|_parent|_search|_self|_top"
Top="integer"
/>
</asp:ImageMap>

Exemples
L'exemple de code suivant montre comment créer de façon déclarative un contrôle ImageMap contenant deux objets CircleHotSpot. La propriété HotSpot..::.HotSpotMode a la valeur HotSpotMode.Navigate, ce qui fait que la page atteint l'URL spécifiée chaque fois qu'un utilisateur clique sur une zone réactive circulaire. Pour que cet exemple fonctionne correctement, vous devez fournir votre propre image pour la propriété ImageUrl et mettre à jour le chemin d'accès à l'image de façon à ce que l'application puisse la localiser.
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head id="head1" runat="server">
<title>ImageMap Class Navigate Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>ImageMap Class Navigate Example</h3>
<h4>Shopping Choices:</h4>
<asp:imagemap id="Shop"
imageurl="Images/ShopChoice.jpg"
alternatetext="Shopping choices"
runat="Server">
<asp:circlehotspot
navigateurl="http://www.tailspintoys.com"
x="145"
y="120"
radius="75"
hotspotmode="Navigate"
alternatetext="Shop for toys">
</asp:circlehotspot>
<asp:circlehotspot
navigateurl="http://www.cohowinery.com"
x="145"
y="290"
radius="75"
hotspotmode="Navigate"
alternatetext="Shop for wine">
</asp:circlehotspot>
</asp:imagemap>
</form>
</body>
</html>
<%@ page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head id="head1" runat="server">
<title>ImageMap Class Navigate Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>ImageMap Class Navigate Example</h3>
<h4>Shopping Choices:</h4>
<asp:imagemap id="Shop"
imageurl="Images/ShopChoice.jpg"
width="150"
height="360"
alternatetext="Shopping choices"
runat="Server">
<asp:circlehotspot
navigateurl="http://www.tailspintoys.com"
x="75"
y="290"
radius="75"
hotspotmode="Navigate"
alternatetext="Shop for toys">
</asp:circlehotspot>
<asp:circlehotspot
navigateurl="http://www.cohowinery.com"
x="75"
y="120"
radius="75"
hotspotmode="Navigate"
alternatetext="Shop for wine">
</asp:circlehotspot>
</asp:imagemap>
</form>
</body>
</html>
L'exemple de code suivant montre comment créer de façon déclarative un contrôle ImageMap contenant deux objets RectangleHotSpot. La propriété ImageMap..::.HotSpotMode a la valeur HotSpotMode.PostBack, ce qui a pour effet de publier la page sur le serveur chaque fois qu'un utilisateur clique sur une zone réactive. Pour que cet exemple fonctionne correctement, vous devez fournir votre propre image pour la propriété ImageUrl et mettre à jour le chemin d'accès à l'image de façon à ce que l'application puisse la localiser.
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub VoteMap_Clicked(ByVal sender As Object, ByVal e As ImageMapEventArgs)
Dim coordinates As String
Dim hotSpotType As String
Dim yescount As Integer
Dim nocount As Integer
If (ViewState("yescount") IsNot Nothing) Then
yescount = Convert.ToInt32(ViewState("yescount"))
Else
yescount = 0
End If
If (ViewState("nocount") IsNot Nothing) Then
nocount = Convert.ToInt32(ViewState("nocount"))
Else
nocount = 0
End If
' When a user clicks the "Yes" hot spot,
' display the hot spot's name and coordinates.
If (e.PostBackValue.Contains("Yes")) Then
yescount += 1
coordinates = Vote.HotSpots(0).GetCoordinates()
hotSpotType = Vote.HotSpots(0).ToString()
Message1.Text = "You selected " & hotSpotType & " " & e.PostBackValue & ".<br />" & _
"The coordinates are " & coordinates & ".<br />" & _
"The current vote count is " & yescount.ToString() & _
" yes votes and " & nocount.ToString() & " no votes."
' When a user clicks the "No" hot spot,
' display the hot spot's name and coordinates.
ElseIf (e.PostBackValue.Contains("No")) Then
nocount += 1
coordinates = Vote.HotSpots.Item(1).GetCoordinates()
hotSpotType = Vote.HotSpots.Item(1).ToString()
Message1.Text = "You selected " & hotSpotType & " " & e.PostBackValue & ".<br />" & _
"The coordinates are " & coordinates & ".<br />" & _
"The current vote count is " & yescount.ToString() & _
" yes votes and " & nocount.ToString() & " no votes."
Else
Message1.Text = "You did not click a valid hot spot region."
End If
ViewState("yescount") = yescount
ViewState("nocount") = nocount
End Sub
</script>
<html >
<head id="head1" runat="server">
<title>ImageMap Class Post Back Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>ImageMap Class Post Back Example</h3>
<asp:imagemap id="Vote"
imageurl="Images/VoteImage.jpg"
width="400"
height="200"
alternatetext="Vote Yes or No"
hotspotmode="PostBack"
onclick="VoteMap_Clicked"
runat="Server">
<asp:RectangleHotSpot
top="0"
left="0"
bottom="200"
right="200"
postbackvalue="Yes"
alternatetext="Vote yes">
</asp:RectangleHotSpot>
<asp:RectangleHotSpot
top="0"
left="201"
bottom="200"
right="400"
postbackvalue="No"
alternatetext="Vote no">
</asp:RectangleHotSpot>
</asp:imagemap>
<br /><br />
<asp:label id="Message1"
runat="Server">
</asp:label>
</form>
</body>
</html>
<%@ page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void VoteMap_Clicked (Object sender, ImageMapEventArgs e)
{
string coordinates;
string hotSpotType;
int yescount = ((ViewState["yescount"] != null)? (int)ViewState["yescount"] : 0);
int nocount = ((ViewState["nocount"] != null)? (int)ViewState["nocount"] : 0);
// When a user clicks the "Yes" hot spot,
// display the hot spot's name and coordinates.
if (e.PostBackValue.Contains("Yes"))
{
yescount += 1;
coordinates = Vote.HotSpots[0].GetCoordinates();
hotSpotType = Vote.HotSpots[0].ToString ();
Message1.Text = "You selected " + hotSpotType + " " + e.PostBackValue + ".<br />" +
"The coordinates are " + coordinates + ".<br />" +
"The current vote count is " + yescount.ToString() +
" yes votes and " + nocount.ToString() + " no votes.";
}
// When a user clicks the "No" hot spot,
// display the hot spot's name and coordinates.
else if (e.PostBackValue.Contains("No"))
{
nocount += 1;
coordinates = Vote.HotSpots[1].GetCoordinates();
hotSpotType = Vote.HotSpots[1].ToString ();
Message1.Text = "You selected " + hotSpotType + " " + e.PostBackValue + ".<br />" +
"The coordinates are " + coordinates + ".<br />" +
"The current vote count is " + yescount.ToString() +
" yes votes and " + nocount.ToString() + " no votes.";
}
else
{
Message1.Text = "You did not click a valid hot spot region.";
}
ViewState["yescount"] = yescount;
ViewState["nocount"] = nocount;
}
</script>
<html >
<head id="head1" runat="server">
<title>ImageMap Class Post Back Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>ImageMap Class Post Back Example</h3>
<asp:imagemap id="Vote"
imageurl="Images/VoteImage.jpg"
width="400"
height="200"
alternatetext="Vote Yes or No"
hotspotmode="PostBack"
onclick="VoteMap_Clicked"
runat="Server">
<asp:RectangleHotSpot
top="0"
left="0"
bottom="200"
right="200"
postbackvalue="Yes"
alternatetext="Vote yes">
</asp:RectangleHotSpot>
<asp:RectangleHotSpot
top="0"
left="201"
bottom="200"
right="400"
postbackvalue="No"
alternatetext="Vote no">
</asp:RectangleHotSpot>
</asp:imagemap>
<br /><br />
<asp:label id="Message1"
runat="Server">
</asp:label>
</form>
</body>
</html>
L'exemple de code suivant montre comment créer un contrôle ImageMap contenant des zones réactives aux comportements différents. La zone d'arrière-plan est définie comme un seul RectangleHotSpot qui est publié sur le serveur. Trois objets RectangleHotSpot sont définis dans la même région. Chacune de ces zones réactives ressemble à un bouton et navigue vers une URL. Lorsqu'un clic est effectué sur un contrôle ImageMap dans une région où deux zones réactives se chevauchent, la zone réactive déclarée en premier est prioritaire. Dans cet exemple, les zones réactives de bouton sont déclarées en premier et la zone réactive d'arrière-plan qui les contient est déclarée en dernier. Par conséquent, l'utilisateur obtient le comportement de l'objet Bouton RectangleHotSpot, et non de l'objet d'arrière-plan RectangleHotSpot, lorsqu'il clique sur une zone réactive de bouton. Pour que cet exemple fonctionne correctement, vous devez fournir votre propre image pour la propriété ImageUrl et mettre à jour le chemin d'accès à l'image de façon à ce que l'application puisse la localiser.
<%@ page language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub ButtonsMap_Clicked(ByVal sender As Object, ByVal e As ImageMapEventArgs)
' When a user clicks the "Background" hot spot,
' display the hot spot's value.
If (e.PostBackValue = "Background") Then
Dim coordinates As String
coordinates = Buttons.HotSpots(3).GetCoordinates()
Message1.Text = "You selected the " & e.PostBackValue & "<br />" & _
"The coordinates are " & coordinates
End If
End Sub
</script>
<html >
<head id="head1" runat="server">
<title>ImageMap Class Mixed HotSpotMode Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>ImageMap Class Mixed HotSpotMode Example</h3>
<!--In this scenario, the ImageMap.HotSpotMode
property is not set, because the
HotSpotMode property is set on each individual
RectangleHotSpot object to specify its behavior.-->
<asp:imagemap id="Buttons"
imageurl="Images/MixedImage.jpg"
width="350"
height="350"
alternatetext="Navigation buttons"
hotspotmode="NotSet"
onclick="ButtonsMap_Clicked"
runat="Server">
<asp:RectangleHotSpot
hotspotmode="Navigate"
NavigateUrl="http://www.contoso.com"
alternatetext="Button 1"
top="50"
left="50"
bottom="100"
right="300">
</asp:RectangleHotSpot>
<asp:RectangleHotSpot
hotspotmode="Navigate"
NavigateUrl="http://www.tailspintoys.com"
alternatetext="Button 2"
top="150"
left="50"
bottom="200"
right="300">
</asp:RectangleHotSpot>
<asp:RectangleHotSpot
hotspotmode="Navigate"
NavigateUrl="http://www.cohowinery.com"
alternatetext="Button 3"
top="250"
left="50"
bottom="300"
right="300">
</asp:RectangleHotSpot>
<asp:RectangleHotSpot
hotspotmode="PostBack"
PostBackValue="Background"
alternatetext="Background"
top="0"
left="0"
bottom="350"
right="350">
</asp:RectangleHotSpot>
</asp:imagemap>
<br />
<asp:label id="Message1"
runat="Server">
</asp:label>
</form>
</body>
</html>
<%@ page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void ButtonsMap_Clicked(object sender, ImageMapEventArgs e)
{
// When a user clicks the "Background" hot spot,
// display the hot spot's value.
if (e.PostBackValue == "Background")
{
string coordinates = Buttons.HotSpots[3].GetCoordinates();
Message1.Text = "You selected the " + e.PostBackValue + "<br />" +
"The coordinates are " + coordinates;
}
}
</script>
<html >
<head id="head1" runat="server">
<title>ImageMap Class Mixed HotSpotMode Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>ImageMap Class Mixed HotSpotMode Example</h3>
<!--In this scenario, the ImageMap.HotSpotMode
property is not set, because the
HotSpotMode property is set on each individual
RectangleHotSpot object to specify its behavior.-->
<asp:imagemap id="Buttons"
imageurl="Images/MixedImage.jpg"
width="350"
height="350"
alternatetext="Navigation buttons"
hotspotmode="NotSet"
onclick="ButtonsMap_Clicked"
runat="Server">
<asp:RectangleHotSpot
hotspotmode="Navigate"
NavigateUrl="http://www.contoso.com"
alternatetext="Button 1"
top="50"
left="50"
bottom="100"
right="300">
</asp:RectangleHotSpot>
<asp:RectangleHotSpot
hotspotmode="Navigate"
NavigateUrl="http://www.tailspintoys.com"
alternatetext="Button 2"
top="150"
left="50"
bottom="200"
right="300">
</asp:RectangleHotSpot>
<asp:RectangleHotSpot
hotspotmode="Navigate"
NavigateUrl="http://www.cohowinery.com"
alternatetext="Button 3"
top="250"
left="50"
bottom="300"
right="300">
</asp:RectangleHotSpot>
<asp:RectangleHotSpot
hotspotmode="PostBack"
PostBackValue="Background"
alternatetext="Background"
top="0"
left="0"
bottom="350"
right="350">
</asp:RectangleHotSpot>
</asp:imagemap>
<br />
<asp:label id="Message1"
runat="Server">
</asp:label>
</form>
</body>
</html>

Informations de version
.NET FrameworkPris en charge dans : 4, 3.5, 3.0, 2.0

Plateformes
Windows 7, Windows Vista SP1 ou ultérieur, Windows XP SP3, Windows XP SP2 Édition x64, Windows Server 2008 (installation minimale non prise en charge), Windows Server 2008 R2 (installation minimale prise en charge avec SP1 ou version ultérieure), Windows Server 2003 SP2
Le .NET Framework ne prend pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.

Sécurité des threads
Tous les membres static ( Shared en Visual Basic) publics de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.

Voir aussi
RéférenceAutres ressources
|