We can use RegisterArrayDeclaration() method to pass an array to javascript as shown below. First parameter will be Array Name and second parameter will be Array item.
ClientScript.RegisterArrayDeclaration("myArray", "'AAA'"); ClientScript.RegisterArrayDeclaration("myArray", "'BBB'"); ClientScript.RegisterArrayDeclaration("myArray", "'CCC'"); ClientScript.RegisterArrayDeclaration("myArray", "'DDD'");
|
When we use above method, array will be rendered in browser as a script shown below:
<script type="text/javascript"> //<![CDATA[ var myArray = new Array('AAA', 'BBB', 'CCC', 'DDD'); //]]> </script>
|
In ASP.NET 1.1, we can call this method using Page.RegisterArrayDeclaration().
Join the conversation! Your thoughts help the community grow.