Thanks for solution.I wrote the code like that and now it is working fine.
protected void Page_Load(object sender, EventArgs e)
{
Ajax.Utility.RegisterTypeForAjax(typeof(Login));
if (!IsPostBack)
{
if (Request.Cookies["UName"] != null)
txtUser.Text = Request.Cookies["UName"].Value;
if (Request.Cookies["PWD"] != null)
{
txtUser.Attributes.Add("value", Request.Cookies["UName"].Value);
txtPwd.Attributes.Add("value", Request.Cookies["Pwd"].Value);
}
if (Request.Cookies["UName"] != null && Request.Cookies["PWD"] != null)
RememberMe.Checked = true;
}
}
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)]
public string UserLogin(string uid, string pwd,int id,string chk)
{
try
{
UsersDTO objLogin = new UsersDTO();
objLogin.EmailId= uid;
objLogin.Password= pwd;
UsersBAL objGetUser = new UsersBAL();
int isUser = objGetUser.UserLogin(objLogin);
if (isUser > 0)
{
Session["user"] = uid;
Session["myFav"] = id;
//Start Remember me
if (chk == "true")
{
HttpContext.Current.Response.Cookies["UName"].Value = uid;
HttpContext.Current.Response.Cookies["PWD"].Value = pwd;
HttpContext.Current.Response.Cookies["UName"].Expires = DateTime.Now.AddMonths(2);
HttpContext.Current.Response.Cookies["PWD"].Expires = DateTime.Now.AddMonths(2);
}
else
{
HttpContext.Current.Response.Cookies["UName"].Expires = DateTime.Now.AddMonths(-1);
HttpContext.Current.Response.Cookies["PWD"].Expires = DateTime.Now.AddMonths(-1);
}
//End Remember Me
return "success";
}
else
{
return "User Name/Password is wrong.";
}
}
catch (Exception ex)
{
return "Sorry! Your request can not be updated at this moment. \n\n Error Details:\n" + ex.Message + "\n\n We suggest you to try again in few moments. If this happens very often, please do contact admin.";
}
}