自定义验证控件的简单应用
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
string str = args.Value;
try
{
int i = Convert.ToInt32(str);
if (i % 2 != 0&i>0&i<100)
{
Button1.Text = "输入正确";
CustomValidator1.IsValid = true;
}
else{
CustomValidator1.ErrorMessage="不是奇数";
}
}
catch{
CustomValidator1.ErrorMessage="格式不对";
CustomValidator1.IsValid = false;
}
}
验证文本框输入的为0-100的奇数:这里 CustomValidator1.ErrorMessage="不是奇数"; CustomValidator1.ErrorMessage="格式不对"; 错误信息看不见 是怎么回事?