views:

2457

answers:

4

How do I pass an array I have created on the server side onto the client side for manipulation by Javascript?

Any pseudo code will help

+2  A: 
Joel Coehoorn
You may also want to use it in conjunction with your solution.http://www.aspcode.net/C-encode-a-string-for-JSON-JavaScript.aspx
Ismail
+1  A: 

Convert it to string representation of a javascript array ("['val1','val2','val3']") and shove it into the value field of a hidden input.

StingyJack
+2  A: 

Another way would be to use the RegisterArrayDeclaration method of the Page object (deprecated) or in the ClientScriptManager class. See MSDN for details.

A: 

Easiest way is to convert it to json. Then just put it at the top of the page in a variable. I've found this the best json implementation for .net: http://litjson.sourceforge.net/

Anders Rune Jensen