title: How do I execute javascript in a dynamically-added User Control
body: <p>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. </p>
  
  <p>In the map User Control, there is some Javascript initialising the map:</p>
  
  <pre><code>function initializeMap() {
      if (GBrowserIsCompatible()) {
          var map = new GMap2(document.getElementById('Map'), {size: new
  GSize(336, 200)});
          // set the map controls, set the centre, etc.
      }
  }
  </code></pre>
  
  <p>Problem is: I don't know how to call the <code>initializeMap()</code> method. Because it's dynamically added to the page, any attempt to link it to the calling button by <code>"onClientClick=initializeMap()"</code> for example, gives a JS error, saying the method isn't defined.</p>
  
  <p>I've tried</p>
  
  <pre><code>ClientScript.RegisterStartupScript(this.GetType(), "initializeMap", "&lt;script type=\"text/javascript\"&gt;alert('Here'); initializeMap();&lt;/script&gt;");
  </code></pre>
  
  <p>but I don't think I'm on the right track with that one either.</p>