Sunday, August 12, 2007

How to pass array from ASP.Net to Javascript?

There are scenarios where we have to pass list of values as arrray from ASP.Net to client side (Javascript). And we don't have a clear cut method to accomplish this.

To acheive this do as follows:-

  • Prepare the string of values seperated by commas, say string ArrayString = 'Hythem', 'Apple','Banana'
  • Create the array while passing the values to the javascript

See the code below:-

string ArrayString = 'Hythem', 'Apple','Banana';
ntxtAmt.Attributes.Add("onkeyup", "javascript:testme(new Array(" + ArrayString + ");");


No comments: