I need save login of my Login page in cookie for show every time when page is loaded
I have create for save login in cookie, in Button click event. but, because in the Post Back, Page_Load before button, so when page_load put cookie information in the TextBox, my cookie is empty
What can I do for resolve this?
protected void Page_Load(object sender, EventArgs e)
{
// This time, Cookies["login"].Value is empty
tbLogin.Text = Response.Cookies["login"].Value;
}
protected void Button1_Click1(object sender, EventArgs e)
{
Response.Cookies.Add(new HttpCookie("login", tbLogin.Text));
}
Try using Page.IsPostBack property.
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
tbLogin.Text = Response.Cookies["login"].Value;
}
}
protected void Button1_Click1(object sender, EventArgs e)
{
Response.Cookies.Add(new HttpCookie("login", tbLogin.Text));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.