ASP cookie

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);
        }

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。