When I set the VisibleWhenLoggedIn property of my Login control to false, my Login control automatically becomes invisible even if I'm not logged in. I've already set the Authenticate event to use my own SQL database, but this problem is still persisting. How do I fix this?

Here is the code:

<asp:Login ID="frmLogin" runat="server" onauthenticate="frmLogin_Authenticate" VisibleWhenLoggedIn="False"></asp:Login>
protected void frmLogin_Authenticate(object sender, AuthenticateEventArgs e)
        string email = frmLogin.UserName;
        string pw = frmLogin.Password;

        string connection = "Data Source=[Removed for privacy purposes];
        SqlConnection conn = new SqlConnection(connection);

        string command = "SELECT [EmailAddress], [Password] FROM Members WHERE (EmailAddress = '" + email + "' AND Password = '" + pw + "')";
        SqlCommand cmd = new SqlCommand(command, conn);

        SqlDataReader myReader = cmd.ExecuteReader();
        bool hasContent = myReader.Read();

        if (hasContent == true)
            e.Authenticated = true;
            e.Authenticated = false;
            frmLogin.FailureText = "Incorrect email/password combination.";

did u get any errors or login control wont show up ?


You can refer following code for login control and connection.

protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
          bool Authenticated = false;
          Authenticated = SiteLevelCustomAuthenticationMethod(Login1.UserName, Login1.Password);
          e.Authenticated = Authenticated;
          if (Authenticated == true)
private bool SiteLevelCustomAuthenticationMethod(string UserName, string Password)
          bool boolReturnValue = false;
          // Insert code that implements a site-specific custom 
          // authentication method here.
          // This example implementation always returns false.
          string strConnection  = "server=dtpxp-skumari;database=master;uid=sa;pwd=;";
          SqlConnection Connection = new SqlConnection(strConnection);
          String strSQL = "Select * From Employee";
          SqlCommand command =new SqlCommand(strSQL, Connection);
          SqlDataReader Dr;
          while (Dr.Read())
                    if ((UserName == Dr["name"].ToString()) & (Password == Dr["Password"].ToString()))
                             boolReturnValue = true;
                    return boolReturnValue;

If you want to more detail about login control just go for this below link.