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); }
时间: 2024-10-29 19:10:39