C#

Monday, February 3, 2014

ImageMap Control in ASP.NET using C#

Introduction

ImageMap control in ASP.NET is a part of the HTML specification. The ImageMap control to create an image that defines hotspot regions. When user click on hotspot region the control navigate on another page. Basically the use of ImageMap is to display a map of a geographical region. Each map is divided in hotspot region. When user click on the specific region of map the web page will redirect or navigate on other web page where the additional data will be displayed about that region. You can set the Image path by using ImageUrl property. Another important property is HotSpotMode. In this example we use HotSpotMode="Navigate" and CircleHotSpot for regions. In this example the ImageMap has four television. Each television is divided by CircleHotSpot region with NavigateUrl. When user click the specific region it will redirect on other web page which holds the additional information about that region.
The following are some useful property.

1. ImageUrl: Url of the Image.
2. AlternetText: Appears if image not loaded properly.
3. HotSpotMode: It has three values PostBack, Navigate and Inactive.


Example:

  1. <%@ Page Language="C#" %>  
  2.   
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  4.   
  5. <script runat="server">  
  6.     protected void ImageMap1_Click(object sender, System.Web.UI.WebControls.ImageMapEventArgs e) {  
  7.         Response.Write("You selected: " + e.PostBackValue);  
  8.     }  
  9. </script>  
  10.   
  11. <html xmlns="http://www.w3.org/1999/xhtml">  
  12. <head runat="server">  
  13.     <title>ImageMap Control Example</title>  
  14. </head>  
  15. <body>  
  16.     <form id="form1" runat="server">  
  17.     <div>  
  18.         <asp:ImageMap  
  19.              ID="ImageMap1"  
  20.              runat="server"  
  21.              ImageUrl="~/Images/Dolls.jpg"  
  22.              Width="500"  
  23.              HotSpotMode="PostBack"  
  24.              OnClick="ImageMap1_Click"  
  25.              >  
  26.             <asp:RectangleHotSpot Top="0" Bottom="448" Left="0" Right="250" AlternateText="Sky Doll" PostBackValue="Sky Doll" />  
  27.             <asp:RectangleHotSpot Top="0" Bottom="448" Left="251" Right="500" AlternateText="Red Doll" PostBackValue="Red Doll" />  
  28.         </asp:ImageMap>  
  29.     </div>  
  30.     </form>  
  31. </body>  
  32. </html>  

No comments:

Post a Comment