Dynamically Adding Map to page

May 12, 2009 at 10:03 PM

Ok, I had this working in 3.5 - but now that I've upgraded to 4.0.1 - my map doesn't show up on my page anymore.  I have a place holder and am dynamically adding the GoogleMap as so

GoogleMap map = new GoogleMap();
map.Key = myKey;
map.Latitude = latitude;
map.Longitude = longitude;
map.Height = new Unit("250px");
map.Width = new Unit("250px");
map.Zoom = 9;

But again - nothing has changed except for the new version of Artem.GoogleMaps to version 4.0.1  Please help!!!

May 20, 2009 at 11:54 PM

I'm also having the same issue after upgrading to 4.0.1; here is the html generated by the control.

<div id="ctl00_ContentPlaceHolder1_10_gmap_Templates" style="display:none;"></div><input id="ctl00_ContentPlaceHolder1_10_gmap_State" name="ctl00_ContentPlaceHolder1_10_gmap_State" type="hidden" /></p></div>


May 20, 2009 at 11:58 PM

Here a little more: seems to have an issue on load();

var 9_gmap = new Artem.Web.GoogleMap({"Address":"Via Palermo, 36, 00184 Rom, Rome , Italy","BaseCountryCode":null,"ClientID":"ctl00_ContentPlaceHolder1_9_gmap","ClientMapID":"9_gmap","DefaultAddress":null,"DefaultMapView":0,"Directions":[],"EnableContinuousZoom":false,"EnableDoubleClickZoom":false,"EnableDragging":true,"EnableGoogleBar":false,"EnableInfoWindow":true,"EnableMarkerManager":false,"EnableReverseGeocoding":false,"EnableScrollWheelZoom":false,"Height":"280px","IsStreetView":false,"IsStatic":false,"Key":"ABQIAAAACzady7T3G0PSiGXZswDVtxQp9DW3rTMQ2hBrw-i2kzCNoOjV1xRtmXaPwzYqbWmsrorPyrnuU8sFoA","Latitude":0,"Longitude":0,"MapEvents":{},"MarkerEvents":{},"PolygonEvents":{},"PolylineEvents":{},"ShowMapTypeControl":true,"ShowScaleControl":false,"ShowTraffic":false,"StreetViewMode":0,"StreetViewPanoID":null,"Width":"500px","Zoom":15,"ZoomPanType":0});
9_gmap.addMarker({"Address":"Via Palermo, 36, 00184 Rom, Rome , Italy","AutoPan":true,"Bouncy":false,"Clickable":true,"Draggable":false,"DragCrossMove":false,"IconAnchor":{"X":8,"Y":16},"IconSize":{"Height":16,"Width":16},"IconUrl":null,"InfoWindowAnchor":{"X":0,"Y":0},"Latitude":0,"Longitude":0,"OpenInfoBehaviour":0,"ShadowSize":{"Height":16,"Width":16},"ShadowUrl":null,"Text":"Gulliver's House","Title":"Gulliver's House"});
May 21, 2009 at 5:59 AM


From the both samples above I see you have an ASP.NET control with ID set to a number.
In the first sample it is 10 and in the second is 9.
I will not recommend using plain numbers as control IDs, even if in most cases there is not trouble because generated ClientID and UniqueID wraps that number like (part _10_):

However, from version 4 of GoogleMap control I map the ID of the control directly yo the JS object created for it.
In your case that generates a JS variable 9_gmap, which is JS error - variable name cannot start with a number. 

I would suggest you avoid using ID for the map control like: 10_gmap or 9_gmap.
If this numbers in the IDs are coming from a kind of sequential code generation I would suggest you using the opposite pattern: instead of {number}_gmap, use gmap_{number}


Jun 19, 2009 at 8:52 PM


I still cannot dynamically add a map.  (the first initial post above).  It's works perfect in 3.5 --- I basically have a site that allows custom templating - so I dont' know where on a page a map will be placed (if at all) - That's why the page has a place holder - and I am dynamically creating and adding controls to it.  I get absolutely nothing with the newest version of artem.googlemap.

I did try your suggestion and give the control an ID that starts with a letter - so I added:

map.ID = "googleMap";

And still nothing is displayed.


Ideas?  I appreciate your help!

Jun 20, 2009 at 7:01 AM


I did test exactly your case and it works for me.

Here is my page markup:

<%@ Page Title="" Language="C#" MasterPageFile="~/GoogleMap.master" AutoEventWireup="true" CodeFile="Dynamic.aspx.cs" Inherits="map_Dynamic" %>

<asp:Content ID="Content1" ContentPlaceHolderID="phContent" Runat="Server">
    <asp:PlaceHolder ID="phMap" runat="server"></asp:PlaceHolder>
<asp:Content ID="Content2" ContentPlaceHolderID="phDescription" Runat="Server">
<asp:Content ID="Content3" ContentPlaceHolderID="phProperties" Runat="Server">
<asp:Content ID="Content4" ContentPlaceHolderID="phActions" Runat="Server">
<asp:Content ID="Content5" ContentPlaceHolderID="phIssues" Runat="Server">

And here is my page code behind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

public partial class map_Dynamic : System.Web.UI.Page {

    #region Methods ///////////////////////////////////////////////////////////////////////////

    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void Page_Load(object sender, EventArgs e) {

        string key = ConfigurationManager.AppSettings["GoogleMapKey"];
        double latitude = 42.1229;
        double longitude = 24.7879;

        Artem.Web.UI.Controls.GoogleMap map = new Artem.Web.UI.Controls.GoogleMap();
        map.ID = "googleMap";
        map.Key = key;
        map.Latitude = latitude;
        map.Longitude = longitude;
        map.Height = new Unit("250px");
        map.Width = new Unit("250px");
        map.Zoom = 9;

Please, take a note, I'm adding the control in Page_Load.
Hope same you do.

I'm getting the Key from my AppSettings.
Please, verify carefully you key is a proper for one.
You can do so by adding a standard page and putting a GoogleMap control on that page not dynamically with the same key.
If it is not working even like that, then you have to re-issue your key.



Jun 20, 2009 at 7:10 AM

Just forgot.
You can see the page working online at:

Jun 23, 2009 at 12:50 AM


I found the reason!  I didn't have a ScriptManager on my ascx control (or page).  So if I add one - or bind the runtime to the older versions - I'm good to go (like here: http://dotnetslackers.com/Ajax/re-63468_Using_Older_AJAX_Controls_in_Visual_Studio_2008.aspx)

Now here's another question - how come the 4.x version requires a ScriptManager?  I don't use one on most of my sites that use the 3.5 control - and it still works fine.

Just wierd -- Thanks for your help!

Jun 23, 2009 at 3:42 PM


Sure, it's weird.
I don't have a reference to that in the binaries and using the control on pages without ScriptManager.

If you find any details about the issue, please, let me know.


Jan 26, 2010 at 6:22 PM

No problem getting the map to work. My problem is when I try to add a directions. Any ideas on how to get this working?