Click here to Skip to main content
15,914,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
please provide me a suitable code for image map in asp.net
Posted
Updated 31-Mar-14 0:44am
v2

ImageMap.aspx

XML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ImageMap.aspx.cs" Inherits="ImageMap" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>asp.net ImageMap: how to use</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Red">ImageMap</h2>
        <asp:Label
            ID="Label1"
            runat="server"
            Font-Size="Medium"
            ForeColor="DodgerBlue"
            >
        </asp:Label>
        <br />
        <asp:ImageMap
            ID="ImageMap1"
            runat="server"
            ImageUrl="~/Images/Doll.gif"
            HotSpotMode="PostBack"
            OnClick="ImageMap1_Click"
            >
            <asp:RectangleHotSpot
                 Top="0"
                 Bottom="360"
                 Left="0"
                 Right="180"
                 AlternateText="Green Doll"
                 PostBackValue="Green Doll"
                 />
            <asp:RectangleHotSpot
                Top="0"
                Bottom="360"
                Left="181"
                Right="360"
                AlternateText="Pink Doll"
                PostBackValue="Pink Doll"
                />
        </asp:ImageMap>
    </div>
    </form>
</body>
</html>



====

ImageMap.aspx.cs

C#
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class ImageMap : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack)
        {
            Label1.Text = "Click any doll!";
            ImageMap1.BorderWidth = 3;
            ImageMap1.BorderStyle = BorderStyle.Double;
            ImageMap1.BorderColor = System.Drawing.Color.Crimson;
        }
    }

    protected void ImageMap1_Click(object sender, ImageMapEventArgs e)
    {
        Label1.Text = "You ckecked: " + e.PostBackValue;
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900