Create Clickable sections of image in ASP.NET

This article is about how to create more than one clickable sections in an image in ASP.NET.
  • 3825

Image Map

This article is about how to create more than one clickable sections in an image in ASP.NET. You can specify different sections of an image that are clickable and redirect users depending on the click. In the following example we divide an image into two clickable parts, as you click on one of the image information about the image will appears. Lets see the code snippets:

<%@ Page Language="VB"%>
<script runat="server">
  Protected Sub Imagemap1_Click(ByVal sender As Object, _
    ByVal e As System.Web.UI.WebControls.ImageMapEventArgs)
      Response.Write("Name of this planet is : " & e.PostBackValue)
  End Sub
</script>
<
html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
  <title>ImageMap Control</title>
</head>
<
body>
  <form id="form1" runat="server"><br />
     <asp:ImageMap ID="Imagemap1"
          Runat="server"
          img src="image.jpg"
          Width=300
          OnClick="Imagemap1_Click"
          HotSpotMode="PostBack">
      <asp:RectangleHotSpot Top="0"
          Bottom="225"
          Left="0"
          Right="150"
          AlternateText="Earth"
          PostBackValue="Earth">
      </asp:RectangleHotSpot>
          Bottom="225"
          Left="151"
          Right="300"
          AlternateText="Mars"
          PostBackValue="Mars">
      </asp:RectangleHotSpot>
     </asp:ImageMap>
  </form>
</body>
</html>

Output Window

imgclick1.gif          

imgclick2.gif


You can also create hyperlink on that images to display related web pages of the image. The intention of an image map is to provide an easy way of linking various parts of an image without dividing the image into separate image files.

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.