假如我新建了一个网站,名字为default.aspx,我在里面加一个WEB窗体,命名为crystal.aspx,在default.aspx中有一个textbox1,button1,crystal.aspx中有一个label1,现在想做的是,希望用COOKIE来实现,在default.aspx的textbox1输入值以后,点击button1,转到crystal.aspx,并在label1中显示textbox1中输入的值,谢谢大家
调试欢乐多
然后需要显示的地方在request cookie
COOKIE["value1"]=textbox1.text;crystal.aspx页面Load事件中:
label1.text=COOKIE["value1"];
private void Button1_Click(object sender, System.EventArgs e)
{
HttpCookie myCookie = new HttpCookie("MyTestCookie");
myCookie.Value = this.TextBox1.Text;
Response.Cookies.Add(myCookie); Server.Transfer("WebForm2.aspx",false);
}
WebForm2:
private void Page_Load(object sender, System.EventArgs e)
{
HttpCookie myCookie = new HttpCookie("MyTestCookie");
myCookie = Request.Cookies["MyTestCookie"]; if (myCookie != null)
this.Label1.Text = myCookie.Value;
else
Response.Write("not found");
}
button1_Click()
{
HttpCookie newCookie=new HttpCookie("myCookie");
newCookie.Value=this.TextBox1.Text;
newCookie.expires=DateTime.Now.AddDays(1);//这一行可以自己设置具体的延长时间
newCookie.Path="";自己设置
Response.Cookie.Add(newCookie);}
在crystal.aspx 页面的cs中:
page_load()
{
this.Label1.Text=Response.Cookie["newCookie"].Value;
}
HttpCookie hck;
hck = new HttpCookie("MyCookies", this.TextBox1.Text ); DateTime now = DateTime.Now;
hck.Expires = now.AddHours(1);
Response.Cookies.Add(hck);crystal.aspx 页面 HttpCookieCollection hcc;
hcc = Request.Cookies;
this.Label1.Text = hcc["MyCookies"].Value;