Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So, if I enter a username like, Mike, and click on the password TextBox, an error message displays and says, "User Name Already Exist!!!". Then TextBox 1, 2 and 3 are cleared. Then I enter in a username that is in another database the message displays, "User Name Is Available. Please Create Password.". At this time I can create a new password but if I delete the current username and enter a different one that is not in the database I get this message,"User Name Is Available. Please Create Password." with the same data still in TextBox 2 and 3. I then can create a password using the data from the username that was valid and availble. How can I stop this? That is where I am stuck at.


C#
protected void TextBoxEA_TextChanged(object sender, EventArgs e)
    {
        using (SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString))
        {
            con.Open();

            SqlCommand scmd = new SqlCommand("Select INST_ID, EmailAddress, accessLevel from Table1 where EmailAddress = @TextBoxEA", con);
            SqlCommand scmd2 = new SqlCommand("Select INST_ID, EmailAddress, accessLevel from Table2 where EmailAddress = @TextBoxEA", con);

            scmd.Parameters.Add(new SqlParameter("@TextBoxEA", TextBoxEA.Text));
            scmd2.Parameters.Add(new SqlParameter("@TextBoxEA", TextBoxEA.Text));

            using (SqlDataReader dr = scmd.ExecuteReader())
            {
                while (dr.Read())
                {
                    TextBoxINST_ID.Text = dr["INST_ID"].ToString();
                    TextBoxaccessLevel.Text = dr["accessLevel"].ToString();
                }
            }

            using (SqlDataReader dr2 = scmd2.ExecuteReader())
            {
                while (dr2.Read())
                {
                    TextBoxINST_ID.Text = dr2["INST_ID"].ToString();
                    TextBoxaccessLevel.Text = dr2["accessLevel"].ToString();
                }
            }
            if (IsPostBack)
            {
                string cmdStr = "Select count(*) from Tablepass where EmailAddress='" + TextBoxEA.Text + "'";
                SqlCommand userExist = new SqlCommand(cmdStr, con);
                SqlCommand cmd = new SqlCommand("select INST_ID, EmailAddress from Tablepass", con);
                int temp = Convert.ToInt32(userExist.ExecuteScalar().ToString());
                if (temp == 1)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('User Name Already Exist!!!');", true);
                    TextBoxINST_ID.Text = string.Empty;
                    TextBoxaccessLevel.Text = string.Empty;
                    TextBoxEA.Text = string.Empty;
                }
                else if (temp == 0)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('User Name Is Available. Please Create Password.');", true);
                    //TextBoxINST_ID.Text = string.Empty;
                    //TextBoxaccessLevel.Text = string.Empty;
                    //TextBoxEA.Text = string.Empty;
                }
                
            }
        }
    }
}
Posted
Updated 21-Nov-13 7:10am
v5
Comments
TryAndSucceed 21-Nov-13 11:01am    
I think you might have to set the ReadOnly as false before setting the value. Not sure though.
Computer Wiz99 21-Nov-13 11:04am    
I was thinking about that but it works on the other forms that have the same properties set the same way. And those TextBoxes are used for math operators. I will test it out to see.
I guess Enabled="False" is the problem.
Computer Wiz99 21-Nov-13 11:11am    
No, neither on worked. I have other TextBoxes in the same setup and they clear out. What makes these so different? I will still try different things.
Now remove both the Enabled="False" ReadOnly="True" and try.

1 solution

As per the discussion with OP, the problem was...
Quote:
It only does it when you enter a username that is already in a database. So, if I enter a username like, Mike, and click on the password TextBox, an error message displays and says, "User Name Already Exist!!!". Then TextBox 1, 2 and 3 are cleared. Then I enter in a username that is in another database the message displays, "User Name Is Available. Please Create Password.". At this time I can create a new password but if I delete the current username and enter a different one that is not in the database I get this message,"User Name Is Available. Please Create Password." with the same data still in TextBox 2 and 3. I then can create a password using the data from the username that was valid and availble.

And my suggestion was to...

Codes for clearing the TextBoxes should go first like below...
C#
protected void TextBoxEA_TextChanged(object sender, EventArgs e)
{
    TextBox1.Text = string.Empty;
    TextBox2.Text = string.Empty;
    TextBox3.Text = string.Empty;

    // Now other codes....

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900