Can anyone please tell me how to call javascript function with string arrays as argument and how to use this arrays in the called function. Here is my code:
C# Code
for (int i = 0; i < count; i++)
{
array1[i] = dt.Rows[i]["FieldName"].ToString();
array2[i] = dt.Rows[i]["FieldValue"].ToString();
}
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"Javascript", "<script type='text/javascript'>myFunction('" + count + "','" + array1 + "','" + array2 + "');</script>");
JavaScript
function myFunction(cnt, arr1, arr2)
{
for (i = 0; i < cnt; i++)
{
alert("fname" + arr1[i] + " :fvalue " + arr2[i] + " :count:" + cnt);
}
}
any syntax error in passing array variables.
cntin the JavaScript-Code is thecount-variable from C#-Code stored. So it already is the count, not the array itself.cntis a number, which now makes sense, if OP putsvarbefore i at the start it should work, however based on the answer below, it looks as if my interpretation of the question is way off