phoenix13

导航

 

http://stackoverflow.com/questions/183254/what-is-a-postback

when a button is clicked, data will be send to server as a POST request. After server reply, the page will be refreshed. that is Page_Load() will be called, then the Button_click() will be called. if you don't want the page_load change to data back to old state, use

if (!Page.IsPostBack)
protected void Page_Load(object sender, EventArgs e)
        {
            HttpCookie ck = Request.Cookies["xx"];
            if (ck == null)
            {
                TextBox_info.Text = "hello new user!";
            }
            else if (!Page.IsPostBack)
            {
                TextBox_email.Text = ck[EMAIL];
                TextBox_password.Attributes.Add("value",ck[PASSWORD]);
            }
        }
 protected void Button2_Click(object sender, EventArgs e)
        {
            HttpCookie ck = new HttpCookie("xx");
            string email = TextBox_email.Text;
            string password = TextBox_password.Text;
            
            ck[EMAIL] = email;
            ck[PASSWORD] = password;
            ck.Expires = DateTime.Now.AddMonths(1);
            Response.Cookies.Add(ck);
        }

 

posted on 2015-03-21 08:32  phoenix13  阅读(214)  评论(0编辑  收藏  举报