5,545,925 members and growing! (18,731 online)
Email Password   helpLost your password?
Web Development » ASP.NET » General     Intermediate

ImageMap.NET 2.0

By YDreams

An alternative ImageMap control for ASP.NET 2.0
Windows, .NET, Visual Studio, ASP.NET, Dev

Posted: 2 Mar 2006
Updated: 31 Aug 2006
Views: 45,511
Bookmarked: 28 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
6 votes for this Article.
Popularity: 2.78 Rating: 3.58 out of 5
0 votes, 0.0%
1
0 votes, 0.0%
2
1 vote, 16.7%
3
3 votes, 50.0%
4
2 votes, 33.3%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Introduction

The .NET framework comes with a nice set of web server controls that allows you to code for ASP.NET in a object-oriented manner and hiding the complexity of HTML, scripting and browser versioning. Unfortunately .NET 1.x didn't have a control that could generate image maps. I needed one so I decided to make one myself and make it public here.

My control had a few limitations so I was happy to find out that ASP.NET 2.0 had a ImageMap control. After playing with it, I found that it also has its own limitations. I decided then to create a new version of my ImageMap control for ASP.NET 2.0.

Why another control?

This control can do all that Microsoft's control does plus the following:

  • Assign javascript to the hot spots. For example, you can change the background image when the mouse cursor hovers an hot spot.
  • The hot spots are displayed in design mode. Colored by hot spot mode.
  • The polygon hot spots are defined by a list of vertices instead of a string of coordinates.
  • Image maps can share the same hot spot layout. HTML supports it, why not support it too?
  • Display a description string on the browser's status bar when the mouse cursor hovers on a hot spot.
  • The click event handler's argument supplies a reference to the hot spot and the coordinates where it was clicked.

Assigning Javascript to hot spots

To assign Javascript to an hot spot, you just need to use the Attributes parameter the following way:

YDreams.Web.UI.WebControls.PolygonHotSpot polygonHotSpot = (YDreams.Web.UI.WebControls.PolygonHotSpot)this.ImageMap1.HotSpots["Polygon"];
if (polygonHotSpot != null)
{
    polygonHotSpot.Attributes.Add("onMouseOver", "javascript:alert("hi");");
}

In the demo project you can see how to change the image when the mouse cursor hovers on a hot spot.

Post back handler

The click event handler is slightly different. The last argument gives you a reference of the hot spot the user clicked on and the mouse cursor coordinates relative to the upper-left corner of the control.

    protected void ImageMap1_Click(object sender, YDreams.Web.UI.WebControls.ImageMapClickEventArgs args)
    {
        YDreams.Web.UI.WebControls.HotSpot hotSpot = args.HotSpot;
        int x = args.X;
        int y = args.Y;
    }

Tested browsers

The control has been tested on the following browsers:

  • Microsoft Internet Explorer 6.0
  • Mozilla Firefox 1.5

History

  • 8/31/2006 - Fixed bug that prevented post backs from happening when other controls with AutoPostBack set to true where present.
  • 3/2/2006 - Submitted article.
  • 3/8/2006 - Added actions to toggle hot spots display in design mode.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

YDreams


YDreams develops technology, products and services for two of todays' hottest areas: interactive entertainment and wireless location-based services.

We count on a select group of talents with proven expertise in areas ranging from geographical information systems to software engineering, game design, virtual reality, marketing, communication and design.

Occupation: Web Developer
Location: Portugal Portugal

Other popular ASP.NET articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 30 (Total in Forum: 30) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralPostBackValuememberSopraPol2:34 15 Nov '07  
GeneralThis control is useless because of the Bugsmemberdurden814:28 4 Oct '07  
AnswerRe: This control is useless because of the BugsmemberYDreams4:42 4 Oct '07  
GeneralRe: This control is useless because of the Bugsmemberdurden815:19 4 Oct '07  
GeneralGecamemberGeca1:57 5 Jul '07  
GeneralDynamic image maps?memberBryanMohr2:02 12 Mar '07  
Generalonclick fires repeatedlymemberMihai Drebot2:02 23 Jan '07  
GeneralRe: onclick fires repeatedlymemberkarlitr0s7:55 31 May '07  
GeneralRe: onclick fires repeatedlymemberkarlitr0s0:06 1 Jun '07  
GeneralAjax.Netmemberafriend212349:29 26 Oct '06  
GeneralOnClick Event Fires too Earlymemberft625:38 21 Sep '06  
QuestionRe: OnClick Event Fires too EarlymemberWinterBlade9:50 16 Oct '07  
AnswerRe: OnClick Event Fires too EarlymemberFrans6222:21 21 Oct '07  
GeneralRe: OnClick Event Fires too EarlymemberWinterBlade11:03 26 Oct '07  
GeneralCan the area be colored?membert395010:26 10 Sep '06  
QuestionDLL not foundmembersmart_chetan20:44 22 Aug '06  
AnswerRe: DLL not foundmemberYDreams2:18 31 Aug '06  
GeneralPostback bugmemberBunce15:40 28 Jun '06  
GeneralWhere is the DLL ?membervedcyrus20:53 22 Jun '06  
QuestionClick Event won't firememberBunce19:27 19 Jun '06  
QuestionNo Postbackmemberwallyvis23:41 20 Apr '06  
QuestionRe: No PostbackmemberBunce2:10 18 Jun '06  
QuestionRe: Incompatible with 'AutoPostback' set on dropdown list in same pagememberBunce15:33 18 Jun '06  
AnswerRe: Incompatible with 'AutoPostback' set on dropdown list in same pagememberYDreams2:13 31 Aug '06  
GeneralHow do you startmemberAllomeen18:13 2 Mar '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 31 Aug 2006
Editor:
Copyright 2006 by YDreams
Everything else Copyright © CodeProject, 1999-2008
Web15 | Advertise on the Code Project