Monday 5 March 2012

How To Use Image Map Control In Dot Net


ImageMap.aspx

<%@ 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

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;
}
}


No comments:

Post a Comment