鼠标光速qa设置方法:代码都正确,CustomValidator验证不起作用

来源:百度文库 编辑:高考问答 时间:2024/04/30 17:06:30
我做的ASP.NET程序中,CoustomValidator的代码编写没有错误,绑定也没错,但是控件就是不起作用,望高手帮忙解决,现谢过。代码如下:
private void CustomValidator1_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
{
SqlConnection conn=DB.CreateConn();
string strSel="select count(*) from users where uname='"+this.txtUname.Text+"'";
SqlCommand cmd=new SqlCommand(strSel,conn);

conn.Open();
int count=(int)cmd.ExecuteScalar();
conn.Close();

if(count==0)
{
args.IsValid=true;
}
else
{
args.IsValid=false;
}
}

try this

------------------------------
if(count==0)
{
args.IsValid=false;
}
else
{
args.IsValid=true;
}
------------------------------

if(count==0)
{
args.Enabled=true;
}
else
{
args.Enabled=false;
}