如何在.aspx页面中访问会话值? [英] How do I access Session value in a .aspx page?

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

问题描述

我想在.aspx页面中访问我的会话值,我尝试了很多方法,但它仍然没有显示价值。



  if (DropDownList2.SelectedItem.Text ==  阿拉伯语
会话[ dir] = rtl;
else
会话[ dir] = ltr;



我喜欢这样但无法访问会话值:

  <   html     xmlns   =  http://www.w3.org/1999/xhtml    dir   ='  < span class =code-pagedirective><% #Sessage [  dir ] .ToString()%>'      RUNAT  <跨度class =code-keyword> =  server >  





任何提升都非常感谢

解决方案

您好



试试这个..



 <   html     id   =  htmlid    dir   =  <% #Sessage [  dir]。ToString( )%>     runat   =  server    xmlns   =  http://www.w3.org/1999/xhtml >  <   / html  >  









  //  您可以尝试两种方式..  
// 1)使用属性
// htmlid.Attributes.Add(dir,rtl);
// 2)
会话[ dir] = rtl;
// 设置完html后,你必须调用html控件的这个方法(.DataBind())会话中的值
htmlid.DataBind();


使用Java脚本访问会话值



 <   script    类型  =  text / javascript >  
函数GetUserName()
{

var username ='<% =会话[ UserName] % > ';
alert(用户名);
}
< / script >


你可以使用一个主div,我用这种格式测试它

它正在工作!!!!!!!!!!!



 <   p     dir   =  rtl > 将此文本写入权利 - left!<   / p  >  
< div < span class =code-attribute> dir = &L t;% =会话[ dir] %> >
朋友们好朋友
< / div >





rtl =从右向左文本方向

语法:

< p element dir =ltr | rtl | auto >


I want to access my session value in .aspx page, I try with so many method but still it doesn't show value.

if (DropDownList2.SelectedItem.Text == "Arabic")
            Session["dir"] = "rtl";
        else
            Session["dir"] = "ltr";


I do like this but can't access session value :

<html xmlns="http://www.w3.org/1999/xhtml" dir='<%# Session["dir"].ToString() %>'  runat="server">



Any auggestion really appreciate

解决方案

Hi

Try this..

<html id="htmlid" dir="<%# Session["dir"].ToString() %>" runat="server" xmlns="http://www.w3.org/1999/xhtml"></html>





// You can try in two ways..
//1) using the attributes as
//htmlid.Attributes.Add("dir", "rtl");
//2)
Session["dir"] = "rtl";
// you have to call this method (.DataBind()) of html control after you have set the value in session
htmlid.DataBind();


Accessing Session value Using Java Script

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

        var username = '<%= Session["UserName"] %>';
        alert(username );
    }
</script>


You can use a main div where I have test it in this format
And it's working !!!!!!!!!!!

<p dir="rtl">Write this text right-to-left!</p>
       <div dir="<%=  Session["dir"] %>">
           Hello friends
       </div>



rtl=Right-to-left text direction
Syntax:
<p element dir="ltr|rtl|auto">


这篇关于如何在.aspx页面中访问会话值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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