Use of ImageMap controls in asp.net-basic application

Source: Internet
Author: User

The ASP.net ImageMap control allows you to create an image that contains a number of areas (hot zones) that can be clicked by the user, which are called "Action points." Each action point can be a separate hyperlink or postback event.

Common Properties:

HotSpotMode Property

The HotSpotMode property is used to get or set the default behavior after clicking a hotspot area.
The enumeration values for the HotSpotMode property of the ImageMap control are as shown in the following table:

enumeration value Description
Inactive Without any action, that's like a normal picture without a hotspot area.
NotSet The item is not set and is also the default. Although the name is not set, a directed operation is performed by default, that is, a link to the specified URL address. If no URL address is specified, the default is linked to the application root directory
Navigate The directed action item. Link to the specified URL address. If no URL address is specified, the default is linked to the application root directory
Postback The postback action item. When you click on a hotspot area, the control's click event is triggered

Note: The HotSpotMode property defines the default behavior of click events for all hotspot areas in the picture, but in some cases, because hotspots in a picture are behaving differently, you also need to define hotspotmode properties and their associated properties for each hotspot area separately.

Hotspots Property

The Hotspots property is used to get a collection of hotspots objects.
The ImageMap control consists of an instance of the Hotspot class. A hotspot defines a clickable region in the image map. The ASP.NET framework has 3 kinds of hotspot classes.

CircleHotSpot: Used to define a circular region in an image map.
Rectanglehotspot: Used to define a rectangular region in an image map.
Polygonhotspot: Used to define an irregular shape area in an image map.

Instances of these 3 subclasses of CircleHotSpot, Rectanglehotspot, and Polygonhotspot are called Hotspot objects.

Sample code:

Default.aspx

Copy Code code as follows:

<%@ Page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%>

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> Example 8-4</title>
<link id= "Instancestyle" href= "Stylesheet.css" type= "Text/css" rel= "StyleSheet"/>

<body>
<form id= "Form1" runat= "Server" >
<div>
<fieldset style= "width:290px" >
<legend class= "Maintitle" >imagemap control typical application </legend>
<br/>
<asp:imagemap id= "ImageMap1" runat= "Server" imageurl= "~/image/pic1.png" onclick= "Imagemap1_click" >
<asp:rectanglehotspot alternatetext= "module" bottom= "175" "left=" Navigateurl= "http://localhost/"
right= "target=" "_blank" top= "119"/>
<asp:circlehotspot alternatetext= "Processing 1" hotspotmode= "postback" postbackvalue= "Pro1"
radius= "x=" "241" y= "/>"
<asp:circlehotspot alternatetext= "Processing 2" hotspotmode= "postback" postbackvalue= "Pro2"
radius= "x=" "241" y= "285"/>
<asp:polygonhotspot alternatetext= "Engine" coordinates= "366,118,325,160,372,206,411,161"
Hotspotmode= "Inactive"/>
</asp:ImageMap>
<br/>
<asp:label id= "Labmessage" runat= "Server" ></asp:Label>
</fieldset>
</div>
</form>
</body>

Default.aspx.cs

Copy Code code as follows:

Using System;
Using System.Data;
Using System.Configuration;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;

public partial class _default:system.web.ui.page
{
protected void Page_Load (object sender, EventArgs e)
{
}
protected void Imagemap1_click (object sender, Imagemapeventargs e)
{
String region = "";
Switch (e.postbackvalue)
{
Case "Pro1":
region = "Processing 1";
Break
Case "Pro2":
region = "Processing 2";
Break
}
Labmessage.text = "You clicked is <b>" + region + "&LT;/B&GT;.";
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.