Have you tried calling the "NeedsRefresh" property on the layer?
Im just guessing, but the AJAX viewer is probably creating a new session.
If this is correct, your map is not avalible from within the session
created by the viewer.
Also, be aware that there are TWO types of maps, one called a
Hmm, I see... For some reason this property is not avalible in the API.
You can remove it from the layers collection (code in C#):
MgMap map = ..;
MgMapLayerCollection col = map.GetLayers();
MgMapLayer layer= (MgMapLayer)col[0];
col.RemoveAt(0);
col.Insert(col.Count - 1, layer)
map.Save(...);