Hi,
You are storing cookies for checked Remember me button. So you need to add one condition after first if condition. you can check if cookies exist then you need to manually check that checkbox. You need to do that because control never persist it's value after next postback(refresh page).
And even if credential is stored then you do not need to display that page. just redirect to user's home screen. At the time user click logout, you can remove cookies and user can enter username & password(this will depend upon your requirement).
if (Page.IsPostBack)
{
if (Response.Cookies["mycookie1"] != null)
{
chk_rem.Checked = true;
}
if (chk_rem.Checked)
{
HttpCookie mycookie1 = new HttpCookie("mycookie1");
Response.Cookies.Add(mycookie1);
mycookie1.Values.Add("Username", txt_username.Text);
mycookie1.Values.Add("Password", txt_password.Text);
DateTime dtex = DateTime.Now.AddDays(15);
if (chk_rem.Checked == true)
{
if (Request.Cookies["mycookie1"] != null)
{
HttpCookie getcookie1 = Request.Cookies.Get("mycookie1");
txtUserName.Text = getcookie1.Values["Username"].ToString();
txtPassword.Password = getcookie1.Values["Password"].ToString();
}
}
}
if (chk_rem.Checked == false)
{
Response.Cookies["mycookie1"].Expires = DateTime.Now.AddDays(-1);
}
}
Hope you got the idea from above statement,
Thanks
-Amit Gajjar