The UpdatePanel in Microsoft's ASP.NET AJAX framework has brought pseudo-AJAX to a lot of webpages, but it is in effect nothing but a wrapped postback. Another more overlooked feature in the ASP.NET is ScriptServices. They are webservices called from JavaScript (no cross domain, but still cool). ScriptServices can return either XML or JSON depending on which attribute you mark them with.
The licensed version of the Google Maps .NET Control has direct support for ScriptServices that return a JSON formatted response. The Reimers.Map.JsonMap namespace contains that serialize well to JSON. Using these classes in your response also means that you can convert them directly to Google Maps classes using the built-in converter functions.
Microsoft actually supplies the ScriptIgnore attribute (like XmlIgnore) to help ignore properties during JSON serialization, but since the control has to be compliant with non-ASP.NET AJAX sites I cannot use that attribute.
To exemplify how to use ScriptServices I have uploaded an example to the files list. The zip file contains a page and a webservice. To use the files you must be running an ASP.NET AJAX website with the licensed control (remember you can use the license control with the built-in trial license on localhost addresses).
The example is extremely simple. The map has a clientside click handler that passes the clicked point to the ScriptService. The service in turn calculates a random point 5km from the clicked point and generates a marker there.
As you can see from the example it is possible to create clientside handlers direcltly on the server before the marker is returned, and they are registered automatically.
The ScriptService call is done using the serverside name of the method to be called. The methods parameters are passed in order, then the success callback handler is passed and then the error handler and finally the context.
Servicename.MethodName(parameter1 [parameter2....parameterN], succeshandler, errorhandler, context);
The successhandler receives the response from the server and the context argument from above. If there is a response it is converted and added to the map. Note that the built-in reimers.map.json.convertToGMarker function automatically registers the clientside handlers that were created on the server.
The whole thing is really quite simple and the data transfer is negligible making it extremely responsive. There are however a few caveats. Overlay state is not handled directly by the built-in functions, so you will need to deal with that yourself. I will explain in a later post which tools can make this easy for you. The JSON serialization is quite good at handling character escaping, but don't nest too many quotes in quotes or you are going to get yourself in trouble. Finally you will need to know some JavaScript to use ScriptServices. I have tried to make as many helper methods and functions available but you are going to have to integrate it into your application, so you will need to know how to code it.