views:

162

answers:

1

I have a GridView of thumbnail photos within an UpdatePanel, with clickable icons in each row which each load a User Control containing a small Google Map into the relevant row. The idea is that the user can geotag (by clicking on the map) any photo in the GridView.

In the map User Control, there is some Javascript initialising the map:

function initializeMap() {
    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById('Map'), {size: new
GSize(336, 200)});
        // set the map controls, set the centre, etc.
    }
}

Problem is: I don't know how to call the initializeMap() method. Because it's dynamically added to the page, any attempt to link it to the calling button by "onClientClick=initializeMap()" for example, gives a JS error, saying the method isn't defined.

I've tried

ClientScript.RegisterStartupScript(this.GetType(), "initializeMap", "<script type=\"text/javascript\">alert('Here'); initializeMap();</script>");

but I don't think I'm on the right track with that one either.

A: 

You should be using the ScriptManager to emit your javascript where there is an UpdatePanel involved like so:

ScriptManager.RegisterStartupScript(this, this.GetType(), "initializeMap", "initializeMap();", true);
Naeem Sarfraz
Thanks Naaem, that's what I ended up doing.
Rafe Lavelle