我遇到了这个错误:
找不到类型或命名空间名称“WebControls”(您是否缺少 using 指令或程序集引用?)
源错误:
Line 28: Login Login1 = (WebControls.Login)LoginView1.FindControl("Login1"); // here the error code
Line 29: TextBox UserName = (TextBox)Login1.FindControl("UserName");
Line 30: TextBox FailureText = (TextBox)Login1.FindControl("FailureText");
我做了一些研究,解决方案是将其添加到源代码中:
System.Web.UI.WebControls.Login
但我不知道这段代码可以添加到哪里。起初我尝试将它作为命名空间,但它是错误的。谁能告诉我应该把这段代码放在哪里??
编辑
protected void Login1_LoginError(object sender, System.EventArgs e)
{
//Login Login1 = (WebControls.Login).LoginView1.FindControl("Login1");
Login Login1 = (System.Web.UI.WebControls.Login)LoginView1.FindControl("Login1");
TextBox UserName = (TextBox)Login1.FindControl("UserName");
TextBox FailureText = (TextBox)Login1.FindControl("FailureText");
//There was a problem logging in the user
//See if this user exists in the database
MembershipUser userInfo = Membership.GetUser(UserName.Text);
if (userInfo == null)
{
//The user entered an invalid username...
FailureText.Text = "There is no user in the database with the username " + UserName.Text;
}
else
{
//See if the user is locked out or not approved
if (!userInfo.IsApproved)
{
FailureText.Text = "When you created your account you were sent an email with steps to verify your account. You must follow these steps before you can log into the site.";
}
else if (userInfo.IsLockedOut)
{
FailureText.Text = "Your account has been locked out because of a maximum number of incorrect login attempts. You will NOT be able to login until you contact a site administrator and have your account unlocked.";
}
else
{
//The password was incorrect (don't show anything, the Login control already describes the problem)
FailureText.Text = string.Empty;
}
}
}