Ksnrg Ksnrg - 1 year ago 91
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?


Answer Source

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"]%>';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download