This project is read-only.

How to open Marker On Page Load

Jul 2, 2009 at 2:13 PM
Edited Jul 2, 2009 at 2:15 PM


I've been having trouble trying to make the marker open on my C# content page load.

I have tried the following in my C# codebehine PageLoad event: 

ClientScript.RegisterStartupScript(this.GetType(), "ClientScript", "showInfoWindow(0);");

Which calls this JavaScript on the client:


<script type="text/javascript">
function showInfoWindow(index) {
	var marker = GoogleMap_ContactPage.Markers[index];

But it doesn't popup the marker. Any ideas or help is appreciated.


-- VT



Jul 3, 2009 at 1:23 AM

I found this thread but it doesn't work. Perhaps the new version has a bug to show the markers infowindow on load:

Here is an excerpt from the coordinator "velio":

You shold use OpenInfoWindowHtml method of GoogleMarker.
This is a method which have to be call on the server-side.
Let's say you have GoogleMap control with ID="GoogleMap1", and you have added a marker to it.
Then you can call OpenInfoWindowHtml in Page_Load for example.

GoogleMap1.Markers[0].OpenInfoWindowHtml("This is a content to be opened over the marker when map is loaded");

, or

GoogleMarker marker = new GoogleMarker(LATITUDE, LONGITUDE);
marker.OpenInfoWindowHtml("This is a content to be opened over the marker when map is loaded");

The purpose of that method is exactly you need: to invoke from server side code a info window, with specific content, to be opened over a marker after map is loaded.

Hope this helps.

Jul 7, 2009 at 12:21 PM


The reason is probably you startup script has invoked before the marker is loaded.
Have in mind, the GoogleMap script is a startup script as well and it takes some time to render/load map and the markers.

You can try to put some timeout before invoking you script or even better to use OnClientMapLoad to trigger your script.


Jul 31, 2009 at 6:32 AM

FYI to future readers of this post. The "OnClientMapLoad" directly calling the JavaScript function did not work. I needed to add a timer to delay the call.

So I added the following:

 OnClientMapLoad="setTimeout('showInfoWindow(0)', 1000);"
Oct 28, 2010 at 8:21 PM
Edited Oct 28, 2010 at 8:23 PM

Found how to set the default info opened on page load (I added as a property on the GoogleMarker class in my local copy of the code for easier use).

        /// <summary>
        /// Gets or sets whether the marker's default window is opened on page load.
        /// </summary>
        public bool IsDefaultInfoWindowOpened
            get { return _isDefaultInfoWindowOpened; }
                _isDefaultInfoWindowOpened = value;
                Actions.Add("OnClientMapLoad = setTimeout(\"{0}.Markers[{1}].openDefaultInfoWindow()\", 1000);");

Feb 4, 2011 at 3:59 PM

Hi all,

I've used this code to achieve the original question of this post, but it doesn't work.

private void SetDefaultAddress()
            // First clear all markers on the map

            // Set the default address
            gmap.Address = this.GoogleDefaultMarker;
            // Create a new marker, based on the address
            GoogleMarker marker = new GoogleMarker(this.GoogleDefaultMarker);
            // Set the content for the marker info
            marker.InfoContent.Controls.Add(new LiteralControl(this.GoogleDefaultMarkerInfo));
            marker.Bouncy = true;
            marker.AutoPan = true;

            // Add the marker to the map
        catch (Exception ex)
            throw ex;

In my page I use this Javascript:

<script type="text/javascript">
    function showInfoWindow(index) {
        var marker = gmap.Markers[index];

And the following code on the OnClientMapLoad:

<artem:GoogleMap ID="gmap" OnClientMapLoad="setTimeout('showInfoWindow(0)', 1000);"
    ShowScaleControl="true" Height="400px" runat="server">

What happens is that the page is loaded, a popup appears, but it is empty?

I'de like to have the popup automatically opened, and then beeing centered on the map. It works when I click it, but not automatically.
You can see the desired behaviour here:

Who knows what I'm doing wrong?