tags:

views:

54

answers:

1

I have a requirement to allow users in a content management system to create their own image maps through a gui interface, which I have accomplished. But instead of saving the image map to the page code, I want to save the image map code to a database (sql), which I've also accomplished.
When I started down this road in my head I was thinking the whole time that I'd just add the "usemap" attribute at runtime shown below where promo1.ImageMap holds the entire map code:

if(promo1.HasImageMap) imgPromotion1.Attributes.Add("usemap", promo1.ImageMap);

I guess I didn't think it though well enough, because it seems that "usemap" only expects the name of the existing map to use from the page code, and not the map code as a string.

Does anyone have any clever ideas on how to apply the map from the database to the image at run time?

+1  A: 

You can add a placeholder somewhere on the page and add the imagemap to it from the table when you load it, like the following (note that I'm assuming that promo1.ImageMap is a string that contains the entire imagemap, e.g. <map name="imageMapName" ... </map>):

placeHolder.Controls.Add(new LiteralControl(promo1.ImageMap));

Then, in your code, ensure that the image references the proper name in its usemap attribute:

if(promo1.HasImageMap) 
    imgPromotion1.Attributes.Add("usemap", "#imageMapName");

(Make sure that you use the hatch (pound sign) when referring to the imagemap name whenn adding the attribute.)

Michael Todd
Hi Michael - Based on your first comment and this one with code snippet; you made me realize just how much I was over thinking this. Like you said...it's just a string. It was an easy fix to add a new field for imagemap name to the object so that on creation it gets saved to the db too. So what I have now is..<code> if (_promo1.HasImageMap) { // inject the map litImageMaps.Text += _promo1.ImageMap; // apply the map to this image imgPromotion1.Attributes.Add("usemap", _promo1.ImageMapName); }</code>Works great! Thanks for the slap of reality. :-)
ColoradoRockie