lblMessage会在从文本框中删除文本后触发但仍保持打开状态 [英] lblMessage fires but stays on after deleting text from textbox

查看:112
本文介绍了lblMessage会在从文本框中删除文本后触发但仍保持打开状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一条错误消息,当用户输入已存在的用户名时会触发该消息。错误消息适用于触发部分,但在用户从文本框中删除用户名时不会消失。我怎么能纠正这个?



I have an error message that fire when a user enters a user name that already exist. The error message works for the firing part but will not disappear when the user deletes the user name from the textbox. How can I correct this?

protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
            con.Open();
            string cmdStr = "Select count(*) from TableSecurity where EmailAddress='" + TextBoxEA.Text + "'";
            SqlCommand userExist = new SqlCommand(cmdStr, con);
            SqlCommand cmd = new SqlCommand("select INST_ID, EmailAddress from TableSecurity", con);
            int temp = Convert.ToInt32(userExist.ExecuteScalar().ToString());
            if (temp == 1)
            {
                lblMessage.Text = "User Name Already Exist!!!";
            }
        }
    }

推荐答案

如果要清除用户删除的错误消息用户名,那么你应该考虑在文本框上写入JS验证,包括textchanged,onblur事件等。



但我认为更好的方法是使用customvalidator并添加一个onservervalidate事件,以便您不必关心显示并清除错误消息。



将args.Isvalid属性设置为true或false,如下所示/>


If you want to clear the error message on user delete the username, then you should consider writing JS validation to your textbox ontextchanged, onblur events etc.

But I think the better approach would be to use a customvalidator and add a onservervalidate event for it so that you dont have to takecare about the display and clear of error message.

Set the args.Isvalid property to true or false as below

if (temp == 1)
{
   args.Isvalid=true;
}
else
{
   args.Isvalid=false;
}





希望这有帮助......



Hope this helps...


试试这个:

Try This:
if (temp == 1)
           {
               ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('User Name Already Exist!!!')", true);
           }


这篇关于lblMessage会在从文本框中删除文本后触发但仍保持打开状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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