Reputation: 59
I write a code that gives value from database and saves them in a list and I put list into array and send it to ASP hiddenField. I want to pass this data to JavaScript var as array. How can I do it? I want to save values as string in array.
aspx:
<asp:HiddenField ID="hdnCity_BillMonth" runat="server" />
<asp:HiddenField ID="hdnCount_BillMount" runat="server" />
aspx.vb:
hdnCity_BillMonth.Value = String.Join(",", City)
hdnCount_BillMount.Value = String.Join(",", Value)
City and Value are List
var City_BillMounth ;
var Count_BillMounth;
Upvotes: 1
Views: 253
Reputation: 1649
Since you're joining city values with a "," symbol you can easily convert it into a java script array using split like this:
I assume you are getting your hdnCity_BillMonth values like "city1, city2,city3,...cityN"
var City_BillMounth = [];
City_BillMounth = hdnCity_BillMonth.split(",");
console.log("city Array: "+ City_BillMounth );
do the same for the hdnCount_BillMount
as well.
Upvotes: 1