I have an datatable and for each row i need execute a javascript function (same javascript function, but with diferent values).
For each row, it executed a javascript function and it is returned the result to the code behind (trought web method).
But, with my actual code the function it only execute one time (first row of table).
I have this: c#
string strScript = "";
foreach (DataRow row in dtLodgings.Rows)
{
strScript = strScript + "\n" + "GetInfoGMaps('" + row["Name"].ToString() + "'," + row["Latitude"].ToString().Replace(",", ".") + "," + row["Longitude"].ToString().Replace(",", ".")+ ");";
}
strScript = strScript.Replace("'", "\'");
ClientScript.RegisterStartupScript(GetType(), "GetInfoGMaps", strScript, true);
javascript
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&libraries=places"></script>
var map, service;
function GetInfoGMaps(name, latitude, longitude) {
var loc= null;
if (latitude != "" && longitude != "") {
loc = new google.maps.LatLng(latitude, longitude);
}
map = new google.maps.Map(document.getElementById('map-canvas'), {
center: loc,
zoom: 15
});
service = new google.maps.places.PlacesService(map);
var request = {location: loc, radius: 50000, keyword: name};
service.radarSearch(request, callback); // i got the data and i sent to c# trought ajax
}
c#
[WebMethod]
public static void GetInfoGMaps(InfoMaps lodg)
{
if (lodg != null)
{
// the data is saved in database
}
}
I tried to execute the strString in console (chrome web browser), but I getand undefined and I don't understand why. It seems that when I run radarSearch function gives undefined.
GetInfoGMaps('Mak Albania Resort Durres',41.2314605712891,19.5132293701172);
GetInfoGMaps('Mak Albania Resort Durres',41.2314605712891,19.5132293701172);
GetInfoGMaps('Mak Albania Resort Durres',41.2314605712891,19.5132293701172);
Anyone can help me?
Thanks