Advertisement
Advertisement

新足迹

 找回密码
 注册
新足迹 门户 IT专业论坛 查看内容

ASP.NET 小白问题 #1: session object

2010-11-6 15:18| 发布者: iami | 查看: 1742| 原文链接

众仙!

俺现在遇到一个ASP.NET下关于session 的问题。甚是苦恼。

结构如下
Page 1:
1/. textbox -> to accept a user input (a string, say)
2/. botton -> code behind, to save the user input into the session object
3/. label -> code behind, to retrieve the session["key"], and assign the value to lable.text(dispay)

Page 2:
1/. label -> to do the same job as the label on Page1 (to display the value of the seesion["key"]).

我遇到的问题是这样

问题一:
在第一页上,传textbox.text到session["key"],
然后把值拿出来,赋给label.text,需要cast到String。
但是我发现 (string)或者(String)都能cast.S的大小写都没有关系。
这怎么回事啊,java里没遇到过这种现象。心里很不安,求解

    protected void Button2_Click(object sender, EventArgs e)
    {
        Session["SessionSetting"] = TextBox1.Text;
        Label4.Text = (String)Session["SessionSetting"];
    }

问题二:
原来的session在第一页上没有问题,到第二页上我一定要加上它的namespace Page.Session[]才能工作。
为什么第一页不用加呢?

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Page.Session["SessionSetting"] != null)
            {
                Label4.Text = (string)Page.Session["SessionSetting"];
            }
        }
    }

谢众仙解惑!
Advertisement
Advertisement


Advertisement
Advertisement
返回顶部