Reputation: 287
I encountered this error:
The type or namespace name 'WebControls' could not be found (are you missing a using directive or an assembly reference?)
Source Error:
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");
I did some research and the solution was to add this into the source code:
System.Web.UI.WebControls.Login
but I have no idea where this code can be add into. At first I tried putting it as a namespace, but it was wrong. Anyone can tell me where should I place this code at??
EDIT
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;
}
}
}
Upvotes: 0
Views: 6463
Reputation: 1
As others have pointed out, you need to add:
using System.Web.UI.WebControls;
at the top of your file.
The only thing I can add to this, is that if you get similar errors (after all it can be relatively easy to identify which class to use, but sometimes difficult to identify which namespace to use).
Upvotes: 0
Reputation: 42333
Updated again
Initially, leave the code the same as you've posted - and then add both these using
statements at the top of the .cs file that your code is in:
using System.Web.UI;
using System.Web.UI.WebControls;
I'm thinking the code has mixed it's use of the namespaces here - if doing the above works, I'd then look to get rid of all the WebControls.[class]
type names in favour of just [class]
since the second using eliminates the need to use the WebControls
child namespace explicitly. It's generally bad form to refer to the same type in two different ways in a single code file.
It's also possible that you have another type in your project called Login
which is in another namespace's scope. If this is the case you will need to use the fully-qualified name for the variable you are declaring on line 28.
Upvotes: 1
Reputation: 100248
You need to specify the full name of the class, including all the namespaces and class name itself:
(System.Web.UI.WebControls.LoginView)LoginView1.FindControl("Login1"); // LoginView sic!
or add the namespace to the using block:
using System.Web.UI.WebControls;
...
(LoginView)LoginView1.FindControl("Login1");;
Upvotes: 0
Reputation: 2475
You probably want to add
using System.Web.UI.WebControls;
at the top of your file.
Upvotes: 1