Ksnrg Ksnrg - 7 months ago 41
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"]%>';

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?



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"]%>';