在客户端提取会话值 [英] Extracting Session value at client side

查看:98
本文介绍了在客户端提取会话值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用asp.net应用程序,我的网站正在使用一些会话变量,现在我想知道我的会话值是否在客户端是null但是这样做我从来没有得到空值,只看一下code snippet

I'm using working asp.net app, and my site is using some session variables, now I want to know if my session value is null on client side but doing so I never get the null value, just look at the code snippet

<script type="text/javascript">
 
  function pageLoad() {

     $('#' + '<%= button1.ClientID %>').click(function () {
       var someVariable = '<%=Session["someValue"] %>';
       alert(someVariable);
     });
   }
</script>









这里会话值为null,我应该在someVariable中得到null但是我总是得到存储在会话中的值,例如,如果someValue = 1那么即使Session [someValue,我总是在someVariable中得到1 ] == null,任何想法?谢谢





Here incase of session value is null, I should get null in someVariable but I always get the value that was stored in the session, for example if someValue=1 then I always get 1 in someVariable even if Session["someValue"] == null, any idea ? Thanks

推荐答案

' #' + ' <%= button1.ClientID%>')。click( function (){
var someVariable = ' < span class =code-string><%= Session [someValue]%>';
alert(someVariable);
});
}
< / script>
('#' + '<%= button1.ClientID %>').click(function () { var someVariable = '<%=Session["someValue"] %>'; alert(someVariable); }); } </script>









这里会话值为null,我应该在someVariable中得到null但是我总是得到存储在会话中的值,例如,如果someValue = 1那么即使Session [someValue,我总是在someVariable中得到1 ] == null,任何想法?谢谢





Here incase of session value is null, I should get null in someVariable but I always get the value that was stored in the session, for example if someValue=1 then I always get 1 in someVariable even if Session["someValue"] == null, any idea ? Thanks


如果您执行页面的查看源代码,您将看到上面的行已执行且具有固定值。它始终没有动态。在页面渲染时,设置值然后按原样设置。



如果你想知道会话值,最好是通过隐藏字段,xmlhttprequest等其他方式。
If you do 'View Source' of the page, you will see the line above is executed and have a fixed value. It's not dynamic throughout. While page rendering, the value is set and then it is as is.

If you want to know the session value, better would be to go through other ways like hidden field, xmlhttprequest.


这篇关于在客户端提取会话值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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