แก้ไข

แชร์ผ่าน


ImageMap.HotSpotMode Property

Definition

Gets or sets the default behavior for the HotSpot objects of an ImageMap control when the HotSpot objects are clicked.

public:
 virtual property System::Web::UI::WebControls::HotSpotMode HotSpotMode { System::Web::UI::WebControls::HotSpotMode get(); void set(System::Web::UI::WebControls::HotSpotMode value); };
public virtual System.Web.UI.WebControls.HotSpotMode HotSpotMode { get; set; }
member this.HotSpotMode : System.Web.UI.WebControls.HotSpotMode with get, set
Public Overridable Property HotSpotMode As HotSpotMode

Property Value

One of the HotSpotMode enumeration values. The default is NotSet.

Exceptions

The specified type is not one of the HotSpotMode enumeration values.

Examples

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. The HotSpotMode property is not set on each of the RectangleHotSpot objects because they get their behavior from the ImageMap.HotSpotMode property. 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="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)
  {       
    // When a user clicks the "Yes" hot spot,
    // display the hot spot's value.
    if (e.PostBackValue == "Yes")
      Message1.Text = "You selected " + e.PostBackValue + ".";
       
    else if (e.PostBackValue == "No") 
      // When a user clicks the "No" hot spot,
      // display the hot spot's value.       
      Message1.Text = "You selected " + e.PostBackValue + ".";
      
    else
      Message1.Text = "You did not click a valid hot spot region.";             
  }
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1" runat="server">
  <title>ImageMap.HotSpotMode Example</title>
</head>
  <body>
    <form id="form1" runat="server">
    
      <h3>ImageMap.HotSpotMode Example</h3>
      
      <!--The RectangleHotSpot objects have the post back
        behavior specified by the HotSpotMode 
        property on the ImageMap control.-->
      <asp:imagemap id="Vote"           
        imageurl="Images/VoteImage.jpg"
        alternatetext="Voting choices" 
        hotspotmode="PostBack"
        onclick="VoteMap_Clicked"   
        runat="Server">   
        
        <asp:RectangleHotSpot          
          top="0"
          left="0"
          bottom="354"
          right="250"
          postbackvalue="Yes"
          alternatetext="Vote yes">
        </asp:RectangleHotSpot>
        
        <asp:RectangleHotSpot 
          top="0"
          left="251"
          bottom="354"
          right="500"
          postbackvalue="No"
          alternatetext="Vote no">
        </asp:RectangleHotSpot>
        
      </asp:imagemap>
      
      <br />
      
      <asp:label id="Message1"
        runat="Server">
      </asp:label>
              
    </form>      
  </body>
</html>
<%@ 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)
            
    ' When a user clicks the "Yes" hot spot,
    ' display the hot spot's value.
    If (e.PostBackValue = "Yes") Then
      Message1.Text = "You selected " & e.PostBackValue & "."
       
      ' When a user clicks the "No" hot spot,
      ' display the hot spot's value.
    ElseIf (e.PostBackValue = "No") Then
      Message1.Text = "You selected " & e.PostBackValue & "."
      
    Else
      Message1.Text = "You did not click a valid hot spot region."
                
    End If
  End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1" runat="server">
  <title>ImageMap.HotSpotMode Example</title>
</head>
  <body>
    <form id="form1" runat="server">
    
      <h3>ImageMap.HotSpotMode Example</h3>
      
      <!--The RectangleHotSpot objects have the post back
        behavior specified by the HotSpotMode 
        property on the ImageMap control.-->
      <asp:imagemap id="Vote"           
        imageurl="Images/VoteImage.jpg"
        alternatetext="Voting choices" 
        hotspotmode="PostBack"
        onclick="VoteMap_Clicked"   
        runat="Server">   
        
        <asp:RectangleHotSpot          
          top="0"
          left="0"
          bottom="354"
          right="250"
          postbackvalue="Yes"
          alternatetext="Vote yes">
        </asp:RectangleHotSpot>
        
        <asp:RectangleHotSpot 
          top="0"
          left="251"
          bottom="354"
          right="500"
          postbackvalue="No"
          alternatetext="Vote no">
        </asp:RectangleHotSpot>
        
      </asp:imagemap>
      
      <br />
      
      <asp:label id="Message1"
        runat="Server">
      </asp:label>
              
    </form>      
  </body>
</html>

Remarks

Use the HotSpotMode property to specify the default click behavior of the HotSpot objects within an ImageMap control. This property is set using one of the HotSpotMode enumeration values. The following table lists the possible values.

Item Description
Inactive The HotSpot object does not have any behavior.
NotSet The HotSpot object uses the behavior set by the ImageMap control's HotSpotMode property. If the ImageMap control does not define the behavior, the HotSpot objects all navigate to a URL.
Navigate The HotSpot objects navigate to a URL.
PostBack The HotSpot objects generate a postback to the server.

You can specify a HotSpot object's behavior using either the ImageMap.HotSpotMode property of the ImageMap control or the HotSpot.HotSpotMode property of each individual HotSpot object. If both properties are set, the HotSpot.HotSpotMode property specified on each individual HotSpot object takes precedence over the ImageMap.HotSpotMode property on the ImageMap control.

When you set the HotSpotMode property of the ImageMap control, note that the HotSpotMode.NotSet and HotSpotMode.Navigate values have the same behavior: both navigate to a URL. When you specify HotSpotMode.NotSet for the HotSpot.HotSpotMode property of an individual HotSpot object, that HotSpot determines its behavior from the value of the HotSpotMode property of the ImageMap control.

If you specify HotSpotMode.Navigate for the ImageMap.HotSpotMode property, the page navigates to a URL when the HotSpot is clicked. Use the NavigateUrl property to specify the URL to navigate to.

If you specify HotSpotMode.PostBack for the ImageMap.HotSpotMode property, the page generates a postback to the server when the HotSpot is clicked. Use the PostBackValue property to specify the name of 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.

If you specify HotSpotMode.Inactive for the HotSpot.HotSpotMode property, the HotSpot object does not have any behavior when it is clicked. You can use this value to create an inactive hot spot within a larger active hot spot. This option is provided to allow you to create more complex hot spot zones within an ImageMap control.

To create an inactive area within an active hot spot, you must specify the inactive hot spot before the active hot spot in the ImageMap control. For example, the following ImageMap defines an active ring by specifying an inactive circular hot spot within a larger active circular hot spot:

<asp:ImageMap ID="SaturnImage"   
       ImageUrl="~/saturn.PNG"   
       runat="server" OnClick="SaturnImage_Click">  
    <asp:CircleHotSpot AlternateText="planet" HotSpotMode=PostBack  
          PostBackValue="planet" Radius=40 X=100 Y=100 />  

    <asp:CircleHotSpot HotSpotMode=Inactive   
          Radius=60 X=100 Y=100 />  
    <asp:CircleHotSpot AlternateText="rings" HotSpotMode=PostBack  
          PostBackValue="rings" Radius=80 X=100 Y=100 />  
</asp:ImageMap>  

To cause all HotSpot objects in an ImageMap control to have the same behavior, use the HotSpotMode property on the ImageMap control to specify the behavior. Then, either set the 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 control, set the HotSpot.HotSpotMode property on each individual HotSpot object to either HotSpotMode.Navigate, HotSpotMode.PostBack, or HotSpotMode.Inactive.

Note

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

Applies to

See also