The type or namespace name 'WebControls' could not be found (are you missing a using directive or an assembly reference?)

Posted by user1467175 on Stack Overflow See other posts from Stack Overflow or by user1467175
Published on 2012-06-25T14:34:57Z Indexed on 2012/06/25 21:16 UTC
Read the original article Hit count: 167

Filed under:
|
|
|

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

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET