Fire VB sub on Server from Area Click

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an area setup
<map name="linkmap"><area shape=RECT coords="0,0,135,15" href='<%=LinkDestination1 %>' ><area shape=RECT coords=150,0,285,15 href="<%=LinkDestination2 %>" ><area shape=RECT coords=303,0,394,15 ??? ></map><img src='<%=FullHead %>' border=0 usemap="#linkmap"

Where in VB
FullHead = Me.Request.ApplicationPath + "\images\AdministratorHead.png
LinkDestination1 = Me.Request.ApplicationPath + "\Administration\AdministratorReport.aspx
LinkDestination2 = Me.Request.ApplicationPath + "\Administration\Administrator.aspx

Now what I want is when the 3rd AREA is clicked (303,0,394,15), that a sub in the VB codebehind run on the server. I tried
onclick="<% GetDoc() %>" and it executes GetDoc when the page is loaded but does not make this 3rd area clickable

I thought about just making a button (I really don't want to do that) but this is in my header and not within a form so it won't let me use a button

Any ideas???
 
Hi,

1) you need to reference area OnClick to client side script :
<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 on the client 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.

HTH
Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 
Back
Top