在网站中使用Session的简单例子

前台放两个Button 一个是提交,一个是查询

 

后台:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        string name = this.TextBox1.Text;

        this.Session["Username"] =name;
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        this.Label1.Text =  this.Session["Username"] as string;
    }
}

你可能感兴趣的:(session)