title: help with finding user using directory service account management
body: <p>I'm having an issue when trying to pass the value into the method via a parameter (userName). If I hard code the value, it will find the user. </p>
  
  <p>Any guidance would be greatly appreciated,</p>
  
  <pre><code>protected void btnSubmit_Click(object sender, EventArgs e)
  {
     if (!String.IsNullOrEmpty(txtUserName.Text))
     {
        string userName = txtUserName.ToString();
  
        PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "car2.local", "DC=car2,DC=local");
        UserPrincipal usr = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, userName);
  
        if(usr != null)
        {
           lblStatus.Text = "user exists";
        }
        else
        {
           lblStatus.Text = "user does not exists";
        }
     }
  }
  </code></pre>