This project is read-only.

Server side "Capture Client Click"

Apr 29, 2009 at 5:21 AM
In the capture client click example, with the following javascript -

info.innerHTML = point.lat() + '/' + point.lng();

-- is there any way to do that server side, so I can capture the resulting latitude and longitude, and store it in my database?
Apr 29, 2009 at 7:15 AM
Edited Apr 29, 2009 at 7:16 AM
Hi,

You can handle server-side Click event and in GoogleMap Control 4.0 beta (and the coming soon final release 4.0) as EventArgs you will receive GoogleLocationEventArgs where you have the location on which the client clicked.

Here is a short example:

Markup:

<artem:GoogleMap ID="GoogleMap1" runat="server" Latitude="42.1229" Longitude="24.7879"

    Zoom="5" ShowScaleControl="true" OnClick="HandleClick">

</artem:GoogleMap>


Code-behind:

protected void HandleClick(object sender, GoogleLocationEventArgs e) {

    double lat = e.Location.Latitude;

    double lng = e.Location.Longitude;

    // TODO: store the values in my database

}


Notice the usage of OnClick in the markup above.
Basically you have ability to handle a number client-side and server-side events.
All client-side events has Client in the name. For example to handle the click event on client-side you have to register for OnClientClick.

Regards


Apr 30, 2009 at 5:08 AM
Thanks Velio.  That works, but now I'm getting an unwanted postback.  I'm trying to suppress it as follows, but it's not recognizing it:

    Protected Sub HandleClick(ByVal sender As Object, ByVal e As GoogleLocationEventArgs)
        GoogleMap1.Attributes.Add("onclick", "return false;")
        Dim lat As Double = e.Location.Latitude
        Dim lng As Double = e.Location.Longitude
        txtCaptureLatLon.Text = lat & "/" & lng
    End Sub

Apr 30, 2009 at 7:25 AM
Hi,

If I got you right, you want to register for Click event, receive it once and then unregister.
In that case setting the "onclick" attribute wouldn't work, you have to use RemoveHandler.
So, you code above should be looking similar to:

    Protected Sub HandleClick(ByVal sender As Object, ByVal e As GoogleLocationEventArgs)
        RemoveHandler GoogleMap1.Click, Address of HandleClick
        Dim lat As Double = e.Location.Latitude
        Dim lng As Double = e.Location.Longitude
        txtCaptureLatLon.Text = lat & "/" & lng
    End Sub


Regards
Apr 30, 2009 at 3:03 PM
Works perfectly!  Thank you!!