Calling page server side code from map area.

1) You need to reference area OnClick event to client side script method:

<map name="linkmap">
    <area href="" onclick="return CallServer()" shape="RECT"
coords="0,0,135,150">
</map>
<asp:Image id="Image1" src='image003.gif' border="0" usemap="#linkmap"
runat="server"></asp:image>



2) Your client side script should use __doPostback to trigger postback
with the image control ID as target. Note that I use href to enable hand
cursor. To prevent the page to transfer to other page I disable the
default click event process.

function CallServer()
{
    __doPostBack('Image1','');
    window.event.cancelBubble = true;
    window.event.returnValue = false;   
}


3) to ensure __doPostback existing on the client side I use GetPostBackEventReference in page_load event (server side) :

this.GetPostBackEventReference(this.Image1,"");

 


4) on the server side you should check the form hidden field
__EVENTTARGET for the image ID for image "click" event. Image don't have
Click event so you should check for __EVENTTARGET. alternately you can
create your IMG control that derived from IMG and implement click event.

 

No Comments