Đồng Vọng Đồng Vọng - 10 months ago 61
C# Question

Pass array of array from C# Page Load to use in Javascript function

In Page_Load on server side, I got an array of array as:


(Image to example):

enter image description here

How can I pass that array to client to use in javascript function?

Answer Source

One way, serialize this array and on the page create a JavaScript variable with this serialized value. E.g.

In C#, serialize it -

new JavaScriptSerializer().serialize(Object)

In JS access it -

var arr = <%= serializedArray %>

Other way, when the page loads, create ajax to fetch this data. Refer this article