Ksnrg Ksnrg - 1 month ago 7
Javascript Question

Accessing Asp.Net Session variables in JS

I'm not able to access the variable in my .js file

the code i have at the top of the page is:

<script type="text/javascript">
privilage = '<%=Session["privilage"]%>';
</script>


then i want to access privilage in my .js file.

i just want to alert this at the moment. would i be able to do this?

thanks

Answer

You have to store session Value in HiddenField. After that You can Access the HiddneFieldValue in your JS

    <script type="text/javascript">
     document.getElementById('hdnField').value = '<%=Session["privilage"]%>';
 </script> 
Comments