Đồng Vọng Đồng Vọng - 1 month ago 9
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:

[['1_1','2_1','3_1','4_1'],['1_2','2_2','3_2','4_2'],....]


(Image to example):

enter image description here

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

Answer

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

Comments