UpdatePanel previous markers are retained on subsequent requests

Apr 28, 2010 at 1:30 AM


I have the map control within an update panel. and add markers to the map within a datalists itemDatbound event. on subsequent request (custom paging) the previous markers are retained, it seems all previous javascripts are being sent as well.

The same thing happens if i have a map within a modalpopupextender, each time i show the popup, another marker is added on top of the previous.

any help appreciated.

May 11, 2010 at 4:28 PM

I am having the exact same issue.

May 26, 2010 at 2:45 AM

Try to put a PostBackTrigger with the ControlID property set to your submit button. That worked for me.

May 26, 2010 at 6:10 AM

hi. setting EnableMarkerManager = false. solved the issue. still a problem if it needs to be true though.

also i had a problem with async postbacks. when the map was loaded from an async postback, and any subsequent requests.

within googleMap.cs - OnPreRender, i changed and moved ScriptManager.RegisterClientScriptInclude(Page, GetType(), "maps.google.com", apiUrl); to onLoad. probably all others need this as well.

also, i was trying to reference markers after async postbacks. the intial markers were retained from the previous postbacks. i was trying to reference something like map.markers[x]. but all the previous markers were still there. - although not actually showing on the map

to fix this i added 'script.AppendFormat("{0}.clearMarkers();", id).AppendLine();' before appending the markers within the 'RenderMapScript' function.

cheers, Chris

Sep 13, 2010 at 7:43 PM

I don't think this is a bug.  The control should retain it's state including any markers you created for it across postback.  It should be up to the developer to clear them.  Can't you just call GoogleMap.Markers.Clear() ?

Sep 13, 2010 at 9:37 PM

I see now that this is a bug.  Clearing the markers has no effect and markers and old markers are retained on postback.

Sep 20, 2010 at 4:05 PM
Edited Sep 20, 2010 at 4:06 PM

I now have a fully functional fix for this problem.  The problem is due to a the way the GoogleMap class is defined in the googlemap-4.1.js file.  The Markers class has an array of Markers in it.  However, this variable (and other variables defined for the GoogleMap class) is a static class variable!  When a variable is declared in the prototype in javascript, that causes it to behave like a static class variable in a language like C.  

What happens is that during an ajax postback, the markers on the page will get re-built in a startup script that GoogleMap control makes.  However, because this is an ajax postback, all the Javascript objects from before postback still exist in the memory of the client browser!  And, even though a new GoogleMap is built by the ajax postback, because the Markers member is a static member, all the new markers will simply be added to the array of old members.  This causes the number of markers on the page to DOUBLE after every postback after the first one.  This becomes a big problem very quickly.

To fix the problem, make the following simple changes:

Remove a line here:


    // collections
    Actions: null,
    Directions: null,
    //Markers = [],  <--comment this line out
    Polygons: null,
    Polylines: null,

Add a line here:

Artem.Web.GoogleMap = function Artem$Web$GoogleMap(config) {
    this.Markers = []; // <-- add this line


I think there is a problem with the way classes are defined in the GoogleMap javascript file.  A lot of member variables are defined as static but they should be instance members.