javascript - Get values ​​from a HashTable saved in a session variable -


in asp.net (vb.net) have session variable contain hashtable

dim products hashtable = new hashtable products("example") = "one product" session("products") = products 

now want obtain in client side javascript, value of products("example").

i try this:

<script>     function showsessionvalue() {         // new object         var sessionhasht = {};          // asign hashtable stored in session("products") "sessionhasht"         sessionhasht= '<%=session("products")%>';          // alerts show "undefined" (but no errors):         alert(sessionhasht("example"));         alert(sessionhasht(example));         alert(sessionhasht.example);     }; </script> 

with breakpoint see value of sessionhasht :

sessionhasht = 'system.collections.hashtable'; 

how can values ​​of hashtable javascript?

untested, serialize hashtable json include in script:

// assign hashtable stored in session("products") "sessionhasht" sessionhasht= json.parse('<%= new javascriptserializer().serialize(session("products"))%>'); 

i suppose away not parsing (note lack of quotes):

// assign hashtable stored in session("products") "sessionhasht" sessionhasht= <%= new javascriptserializer().serialize(session("products"))%>; 

you should able use dotted form access items key:

alert(sessionhasht.example); 

Comments