i wrote this code to pass array from asp.net code to javascript:
aspx File:
<script type="text/javascript">
var loc_array;
var loc_array_two;
function AssignValues(loc, loc_two){
loc_arary= loc;
loc_array_two = loc_two;
alert(loc_array[0]);
}
</script>
aspx.cs File:
StringBuilder sb = new StringBuilder();
sb.Append("var loc = [");
foreach (var str in lb1) //lb1 is list
{
sb.Append("['" + str.Value1 + "','" + str.Value2 + "','" + str.Value3 + "'],");
}
sb.Append("];");
StringBuilder sb2 = new StringBuilder();
sb2.Append("var own = [");
foreach (var str2 in lb2) //lb2 is list
{
sb2.Append("['" + str2.Value1 + "','" + str2.Value2 + "','" + str2.Value3 + "'],");
}
sb2.Append("];");
if (lb1.Count > 0 && lb2.Count > 0)
{
string arrayStr1 = string.Format("[{0}]", sb.ToString().TrimEnd('{','}'));
string arrayStr2 = string.Format("[{0}]", sb.ToString().TrimEnd('{', '}'));
Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "AssignValues(" + arrayStr1 + "," + arrayStr2 + ")", true);
}
The array that created is [var loc = [['New York','33.6306686','73.1175653'],];]
- Now this array passed to the function of javascript. But nothing prints. Can anyone help me to solve this problem.