How to create dynamic ASP: ImageMap

I want to create ASP: ImageMap with dynamic hotspot count. I have tried the code below, but it complains that the relay is nested in the image map. Any ideas on how to do this?

    <asp:ImageMap ID="imgMap" runat="server" ImageUrl="~/circles.png" 
                  HotSpotMode="PostBack">
       <asp:Repeater runat="server" id="repeat" DataSource=<%#circles %>>
            <asp:CircleHotSpot PostBackValue="<%#name %>" 
                               Radius="<%#r %>" 
                               X="<%#x %>" 
                               Y="<%#y %>" />
        </asp:Repeater>
    </asp:ImageMap> 

      

(Please ignore data binding issues. I will resolve them later.)

0


source to share


2 answers


You cannot place a repeater inside another server tag. The way to dynamically add hotspots to an ImageMap is to dynamically add them to the code behind. You should be able to use something similar to this in the page load event:

CircleHotSpot hotSpot = new CircleHotSpot();
hotSpot.PostBackValue = "xxxx";
hotSpot.X = xx;
hotSpot.Y = yy;
hotSpot.radius = r;
imgMap.HotSpots.Add(hotSpot);

      



Please forgive that the exact syntax probably doesn't work a bit since I haven't written this code in a while, but you should get the idea. If you want to add multiple hotspots, you can insert this block of code in your for / foreach loop and iterate over the list you want to turn into hotspots.

0


source


Do you need to use a server control or can you do it in plain HTML? something like that:



<map id="map1">
    <asp:Repeater ID="rep" runat="server">
    <ItemTemplate>
    <div align=center> 

    <area href="<%# DataBinder.Eval(Container.DataItem,"page")%>" 
     shape="circle" 
     coords="<%# DataBinder.Eval(Container.DataItem,"Coords")%>" 
     alt="area1" />
    </ItemTemplate>
    </asp:Repeater>
    </map>
    <img src="Images/HPIM1784.jpg" alt="bajs" usemap="#map1" />

      

0


source







All Articles