title: JS global variable reseting when js function is called from C#
body: <p>I create some markers on a google Map. I call the create marker function from c#</p>
  
  <pre><code>  for(int a = 0; a&lt;cpt;a++)
          {
              jsFunc = "myglobalObject.createMarker(" + nearestStations[a][0] + "," + HttpUtility.JavaScriptStringEncode("test", true) + ")";
              ScriptManager.RegisterClientScriptBlock(this, GetType(), "script" + a, "$(function () {" + jsFunc + "; });", true);
          }
  </code></pre>
  
  <p>My js looks like this :</p>
  
  <pre><code> var markers = [];
      var infoWindowIsSet = false;
      myglobalObject = {
  
          map: false,
          prev_infowindow: false, 
  
          initializeMap: function () {
              $(document).ready(function () {
                  var adresseConnexion = document.getElementById("tbAdresseDefault").value;
                  var geocoder = new google.maps.Geocoder();
  
                  mapOptions = {
                      zoom: 6,
                      center: { lat: 46, lng: 1 },
                      language: "en-US",
                      mapTypeId: google.maps.MapTypeId.ROADMAP
                  }
                  myglobalObject.map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
  
  
                  geocoder.geocode({ 'address': adresseConnexion }, function (results, status) {
                      if (status == 'OK') {
  
                          myglobalObject.map.setCenter(results[0].geometry.location);
                          myglobalObject.createMarker(results[0].geometry.location, "test");
                          console.log(results[0].geometry.location);
                      } else {
                          alert('Adresse incorrecte ');
                      }
                  });
  
  
  
  
  
  
              });
          },
  
          createMarker: function (position, information) { 
              marker = new google.maps.Marker({
                  position: position,
                  map: myglobalObject.map,
  
              });
              markers.push(marker);
  
              google.maps.event.addListener(marker, "click", function () {
  
                  infowindow = new google.maps.InfoWindow({ content: information });
                  if (myglobalObject.prev_infowindow) {
                      myglobalObject.prev_infowindow.close();
                  }
  
  
                  myglobalObject.prev_infowindow = infowindow;
                  infowindow.open(myglobalObject.map, this);
                  infoWindowIsSet = true;
  
              });
              google.maps.event.addListener(myglobalObject.map, "click", function () { 
                  if (infoWindowIsSet)
                      infowindow.close();
  
              });
  
              return marker;
  
          }
       }
  </code></pre>
  
  <p>As you can see, I have a map variable in "myglobalObject" that I set here :</p>
  
  <pre><code>                myglobalObject.map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
  </code></pre>
  
  <p>However, after calling the createrMarker func from C#, the variable map seems to be reseted to "false" so the parts where I need it in createMarker are failing. I tried to put map as a global variable and it still failed. What could I do ?</p>
  
  <p>The .cs code : </p>
  
  <pre><code>public string[][] nearestStations = new String[100][];
      protected void Page_Load(object sender, EventArgs e)
      {
  
  
      }
      protected void Page_LoadComplete(object sender, EventArgs e)
      {
          parsingXMLDistance();
      }
  
  
  
  
      public  void parsingXMLDistance()
      {
          double latOfYourStation = double.Parse(GetLatLng(tbAdresseDefault.Text)[0], CultureInfo.InvariantCulture);
          double lngOfYourStation = double.Parse(GetLatLng(tbAdresseDefault.Text)[1], CultureInfo.InvariantCulture);
  
          string latStr, lngStr;
          int cpt = 0;
          for (int j = 0; j &lt; 100; j++)
              nearestStations[j] = new String[1];
          string jsFunc;
          PDV.pdv_liste l = new PDV.pdv_liste();
          l = (litXMLListe("myXMLFile"));
  
          for (int i = 0; i &lt;l.pdv.Length; i++)
          {
              System.Diagnostics.Debug.Write(i + "\r\n");
              if (l.pdv[i].latitude != "" &amp;&amp; l.pdv[i].longitude != "") {
                  if (DistanceTo(latOfYourStation, lngOfYourStation, double.Parse(l.pdv[i].latitude, CultureInfo.InvariantCulture) / 100000, double.Parse(l.pdv[i].longitude, CultureInfo.InvariantCulture) / 100000) &lt; double.Parse(tbDistDefault.Text, CultureInfo.InvariantCulture) )
                  {
                      latStr = "" + double.Parse(l.pdv[i].latitude, CultureInfo.InvariantCulture) / 100000;
                      lngStr = "" + double.Parse(l.pdv[i].longitude, CultureInfo.InvariantCulture) / 100000;
                      latStr = latStr.Replace(',', '.');
                      lngStr = lngStr.Replace(',', '.');
                      nearestStations[cpt][0] = "{lat:" + latStr + ",lng:" + lngStr + "}";
  
                      cpt++;
  
                  }
              }
          }
  
         for(int a = 0; a&lt;cpt;a++)
          {
              jsFunc = "myglobalObject.createMarker(" + nearestStations[a][0] + "," + HttpUtility.JavaScriptStringEncode("test", true) + ")";
              ScriptManager.RegisterClientScriptBlock(this, GetType(), "script" + a, "$(function () {" + jsFunc + "; });", true);
          }
  
      }
  </code></pre>