效果:

(一)发送页面

1、将在TextBox控件中输入的字符串保存至Session对象中;

5-12 session对象实例

2、将在TextBox控件中输入的数组保存至Session对象中;

5-12 session对象实例

3、将在日历表中选中的对象保存至Session对象中;

5-12 session对象实例

4、用SessionAdd方法对重名的Key进行设置(目标位第一个控件),刷新页面后第一个控件值被第四个覆盖掉;

5-12 session对象实例

5、点击超链接,跳转页面;

(二)读取页面(read页面,所有代码都写在PageLoad事件当中)

1、读取第一个文本框内容:

5-12 session对象实例

5-12 session对象实例

2、获取数组:

5-12 session对象实例

5-12 session对象实例

3、获取控件:

5-12 session对象实例

4、遍历session:

Label1.Text=" ";

foreach(string _key in Session.Keys)

{Label1.Text+=("["+_key+"]&nbsp;@nbsp;"+Session[_key].GetType().ToString()+"<br/>")

5、获取SessionID:

Label2.Text=Session.SessionID.ToString();

6、获取Session的剩余时间:

Label3.Text=Session.Timeout.ToString();

7、删除全部session:

protected void Button1_Click(object sender, EventArgs e)

{

    Session.Abandon();

    Response.Redirect(Request.Url.LocalPath.ToString());//通过该方法,可以直接

}

8、删除单个session:

protected void Button2_Click(object sender, EventArgs e)

{

    Session.Remove("ss_txt");

    Response.Redirect(Request.Url.LocalPath.ToString());

}

5-12 session对象实例


5-12 session对象实例


5-12 session对象实例




相关文章:

  • 2022-03-02
  • 2021-08-01
  • 2021-07-20
  • 2021-09-30
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-01
  • 2022-12-23
  • 2021-07-26
  • 2022-12-23
  • 2022-01-08
  • 2021-07-06
  • 2021-05-02
相关资源
相似解决方案