2010-07-05 123 views
0

我已經登錄頁面和它的工作很好,但還記得我複選框沒有工作,我可以不知道哪裏錯誤,請任何人能幫助我,這是我的代碼登錄頁面錯誤

公共部分類_Default: System.Web.UI.Page { public TextBox 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"; 
    } 


} 

}

回答

0

謝謝你更多我得到了答案,這個正確的代碼

公共部分類_Default:System.Web.UI.Page { 公衆的TextBox Usertxt,Passwordtxt; public Literal LBL; public CheckBox CHB;

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


} 

}