清除文本框中的文本无法正常工作。 [英] Clearing out text in a textbox not working.

查看:54
本文介绍了清除文本框中的文本无法正常工作。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,如果我输入像Mike这样的用户名,并单击密码TextBox,则会显示一条错误消息,并显示用户名已存在!!!。然后清除TextBox 1,2和3。然后我输入消息显示在另一个数据库中的用户名,用户名可用。请创建密码。。此时我可以创建一个新密码,但如果我删除当前用户名并输入一个不在数据库中的用户名,我会收到此消息用户名可用。请创建密码。使用相同的数据仍然在TextBox 2和3中。然后,我可以使用有效且可用的用户名中的数据创建密码。我怎么能阻止这个?这就是我被困在的地方。





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.


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

推荐答案

根据与OP的讨论,问题是......

As per the discussion with OP, the problem was...
Quote:

只有当您输入已存在于数据库中的用户名时才会执行此操作。因此,如果我输入像Mike这样的用户名,然后单击密码TextBox,则会显示一条错误消息,并显示用户名已存在!!!。然后清除TextBox 1,2和3。然后我输入消息显示在另一个数据库中的用户名,用户名可用。请创建密码。。此时我可以创建一个新密码,但如果我删除当前用户名并输入一个不在数据库中的用户名,我会收到此消息用户名可用。请创建密码。使用相同的数据仍然在TextBox 2和3中。然后我可以使用有效且可用的用户名数据创建密码。

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.



我的建议是... < br $>


清除TextBoxes的代码应该如下所示......


And my suggestion was to...

Codes for clearing the TextBoxes should go first like below...

protected void TextBoxEA_TextChanged(object sender, EventArgs e)
{
    TextBox1.Text = string.Empty;
    TextBox2.Text = string.Empty;
    TextBox3.Text = string.Empty;

    // Now other codes....

}


这篇关于清除文本框中的文本无法正常工作。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆