Pass array (or TList) from C# code behind to external javascript?

796 Views Asked by At

I need to pass a list (or array) of IP addresses and other information from C# code behind to the javascript function, which is in the external .js..

Also, this list may be long (1000+ items) .. What is the most efficient way to do this? can you provide a small example? should I use json serialization?

1

There are 1 best solutions below

0
On

var myObject = <%= JustSerializeAsJson(...) %>; ... or pass it to a function to whatever. Point is JSON is a valid JavaScript literal so you can drop it in a number of places. Don't worry about "efficiency" here unless there is a profiled problem. Both the generation and JavaScript parsing should be really fast. (Bing maps loads like 1MB file in JS!)

MSDN JSON Serializer