在JS中访问Asp.Net会话变量 [英] Accessing Asp.Net Session variables in JS

查看:103
本文介绍了在JS中访问Asp.Net会话变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法访问我的.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>

然后我想在我的.js文件中访问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?

谢谢

推荐答案

你必须在HiddenField中存储会话值。
之后您可以在JS中访问HiddneFieldValue

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> 

这篇关于在JS中访问Asp.Net会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆