Asp.net 登录页面错误

Asp.net 登录页面错误,asp.net,Asp.net,我有一个登录页面,它工作得很好,但记住我复选框工作得不好,我不知道错误在哪里,请任何人帮助我这是我的代码 公共部分类\u默认值:System.Web.UI.Page { 公共文本框Usertxt,Passwordtxt protected void Page_Load(object sender, EventArgs e) { Usertxt = (TextBox)Login1.FindControl("UserName"); Passwordtxt = (TextBox)Log

我有一个登录页面,它工作得很好,但记住我复选框工作得不好,我不知道错误在哪里,请任何人帮助我这是我的代码

公共部分类\u默认值:System.Web.UI.Page { 公共文本框Usertxt,Passwordtxt

protected void Page_Load(object sender, EventArgs e)
{
    Usertxt = (TextBox)Login1.FindControl("UserName");
    Passwordtxt = (TextBox)Login1.FindControl("Password");
    if (!IsPostBack)
    {
        if (Request.Cookies["Mycookie"] != null)
        {
            HttpCookie Cookie = Request.Cookies.Get("Mycookie");
            Usertxt.Text=Cookie.Values["UserName"];
            Passwordtxt.Text=Cookie.Values["Password"];


        }
    }

}
protected void LoginButton_Click(object sender, EventArgs e)
{
    Usertxt = (TextBox)Login1.FindControl("UserName");
    Passwordtxt = (TextBox)Login1.FindControl("Password");
    Literal LBL;

    LBL = (Literal)Login1.FindControl("FailureText");

    if (FormsAuthentication.Authenticate(Usertxt.Text, Passwordtxt.Text))
    {
        Response.Redirect("");

    }
    else
    {
        Login1.FindControl("FailureText");
        LBL.Text = "error ocurred";
    }


}

}谢谢你,我得到了答案,这是正确的代码

公共部分类\u默认值:System.Web.UI.Page { 公共文本框Usertxt,Passwordtxt; 公共语言; 公共卫生局

protected void Page_Load(object sender, EventArgs e)
{
    Usertxt = (TextBox)Login1.FindControl("UserName");
    Passwordtxt = (TextBox)Login1.FindControl("Password");
    if (!IsPostBack)
    {
        if (Request.Cookies["MyCookie"] != null)
        {
            HttpCookie Cookie = Request.Cookies.Get("MyCookie");
            Usertxt.Text = Cookie.Values["UserName"];
            Passwordtxt.Text = Cookie.Values["Password"];
        }
    }

}
protected void LoginButton_Click(object sender, EventArgs e)
{


    Usertxt = (TextBox)Login1.FindControl("UserName");
    Passwordtxt = (TextBox)Login1.FindControl("Password");
    CHB = (CheckBox)Login1.FindControl("RememberMe");
    LBL = (Literal)Login1.FindControl("FailureText");

    HttpCookie MyCookie = new HttpCookie("MyCookie");
    bool IsRememberme = CHB.Checked;
    if (IsRememberme)
    {
        MyCookie.Values.Add("UserName", Usertxt.Text);
        MyCookie.Values.Add("Password", Passwordtxt.Text);
        MyCookie.Expires = DateTime.Now.AddDays(15);

    }
    else
    {
        MyCookie.Values.Add("UserName", string.Empty);
        MyCookie.Values.Add("Password", string.Empty);
        MyCookie.Expires = DateTime.Now.AddDays(5);

    }
    Response.Cookies.Add(MyCookie);




    if (FormsAuthentication.Authenticate(Usertxt.Text, Passwordtxt.Text))
    {

        Response.Redirect("");

    }
    else
    {
        Login1.FindControl("FailureText");
        LBL.Text = "error ocurred";
    }


}
}