GoogleMap 2.8: Client side events handlers don't seem to work

Feb 18, 2008 at 2:24 AM
Hi all and especially to Velio (thx for your great work!),

I'm trying to use the OnClientClick functionality of the GoogleMap control and it worked wonderfully in release 2.7 as demonstrated in the "capture position sample" http://www.codeplex.com/googlemap/Wiki/View.aspx?title=Capture%20Position%20Sample.

Now I updated to 2.8 but now I can't get it back to work, i.e. my handler function doesn't get called when the client click event is fired. I can see that the event is fired because when I do sth. like this

OnClientClick="alert('fire!')"

it works. But when I assign my client javascript function

function clientShowPosition(overlay,position) {
alert("in the function");
if(position) {
alert("lat:" + position.lat() + " lng:" + position.lng());
var el = document.getElementById('<%= tbLatitude.ClientID %>');
el.value = position.lat();
el = document.getElementById('<%= tbLongitude.ClientID %>');
el.value = position.lng();
}
}

like this: OnClientClick="clientShowPosition"

it does not get called :-( Do you have any clue why? Like I said, the same code worked back in 2.7, although I've seen that changes have been made right around there.

I tried the server side event handler and it worked, but there I have the problem that I don't know how to get the coordinates that were clicked...

Any help is greatly appreciated!

Good night,
Oliver
Coordinator
Feb 18, 2008 at 8:10 AM
Hi,
Thanks.
Try setting OnClientClick like this:
OnClientClick="clientShowPosition(overlay,position)"

Regards
Feb 18, 2008 at 10:36 AM
Hi again,

thanks for your hint. Since I'm quite new to JavaScript, I unfortunately didn't try that way of assigning before. So I tried it - and it still didn't work! Well, hail Firebug: somehow it seems that the parameters of the handler function must be called EXACTLY the same way as they are in the GoogleMap.js, where it says

if(config.events.click) { handler = function(overlay, point) { eval(config.events.click); }; ... }

So I did that - and finally it works :-)

How would the server side handler have to be defined to get that same information, i.e. overlay and point coordinates? Is the GoogleMap.js the right place to look for the handler signatures?

Well, thanks again for your help, last night I was really frustrated - now I feel much better ;-)

Have a good day,
Oliver