c# - Access Javascript global variables at page load -


i adding elements javascript array database using code behind here code:

protected void loadplaces() {   try {     datatable dt = cs.executeqry(@"select location_coords igr.locationdata ", null);     string script = "";     foreach(datarow dr in dt.rows) {       string coord = "placepoints=[";       bool isnotfirst = false;       foreach(string c in dr[0].tostring().trim().split('\n')) {         if (isnotfirst) coord += ",\n";         coord += @"new google.maps.latlng(" + c.trim().split(';')[0].split(':')[1] + "," + c.trim().split(';')[1].split(':')[1] + @") ";         isnotfirst = true;       }       coord += "];";       script += coord;       //scriptmanager.registerstartupscript(page, gettype(), "addpointstomap", coord, true);     }     scriptmanager.registerclientscriptblock(page, gettype(), "setmap", script, true);    } catch (exception ex) {     alert(ex.message);   } } 

i called function page_load(), when tried access map variable, undefined, how can overcome problem added 1 button page , called above function on button click button, @ time javascript variable map ok. javascript code

map = new google.maps.map(document.getelementbyid('map-canvas'), mapoptions);  addplace = function (place) {   if (place == null) return;   var mark = new google.maps.polygon({     paths: place,     strokecolor: '#f50',     strokeopacity: 0.5,     strokeweight: 2,     fillcolor: '#faa',     clickable: true,     fillopacity: 0.7   });   mark.setmap(map);   places.push(mark);    google.maps.event.addlistener(place, 'click', function (event) {     var vertices = this.getpath();     var strvertices = '';     (var = 0; < vertices.getlength(); i++) {       strvertices.value += 'a' + + ':' + vertices.getat(i).lat() + ';';       strvertices.value += 'b' + + ':' + vertices.getat(i).lng();       strvertices.value += '\n';     }     console.debug(strvertices);   }); } 

where writing javascript code?

write javascript code @ bottom of body tag or end of form these variables accessable.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -