How to pass array from Asp.net server side to Javascript function on client side

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

Answers


You'll need to embed it as a javascript array declaration into the page. There are a number of ways to do this, but it generally means turning the array into text that you write to the page, probably using the ClientScriptManager.

I'm hoping for better javascript integration in a upcoming verison of ASP.Net. Moving the value of a server variable —any server variable— to the client ought to be supported with a simple, one-line function call. Not the back-flips we need right now.


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


Need Your Help

How to delete old packages from repository?

linux repository centos

I have a FTP server which I use for Linux repository for RPM packages. I need to delete old packages without doing it manually. Is there a script which can delete old packages based on package vers...

How do I stop GameObjects from respawning at every frame?

c# unity3d coroutine

I've come across this little issue which I can't seem to fully understand how to solve, I've tried changing my codes countless times but I haven't gotten anywhere :(

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.