假如我新建了一个网站,名字为default.aspx,我在里面加一个WEB窗体,命名为crystal.aspx,在default.aspx中有一个textbox1,button1,crystal.aspx中有一个label1,现在想做的是,希望用COOKIE来实现,在default.aspx的textbox1输入值以后,点击button1,转到crystal.aspx,并在label1中显示textbox1中输入的值,谢谢大家

解决方案 »

  1.   

    页面传值。直接post就可以过去吧?
      

  2.   

    先写cookie
    然后需要显示的地方在request cookie
      

  3.   

    能不能写行具体点呢,比如在default.aspx和crystal.aspx中的代码,我是新手,望大家帮忙啊
      

  4.   

    button1点击事件中:
    COOKIE["value1"]=textbox1.text;crystal.aspx页面Load事件中:
    label1.text=COOKIE["value1"];
      

  5.   

    WebForm1:
            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");
    }
      

  6.   

    在default.aspx的cs中:
    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;
    }
      

  7.   

    default.aspx 页面
     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;