例如,有CustomValidator:
protected void CheckAge_ServerValidate(object source, ServerValidateEventArgs args)
{
if (//conditions)
{
args.IsValid = false;
CheckAge_CustomValidator.ErrorMessage = "Error!";
}
else
args.IsValid = true;
} 我想在Page_Load ()中调用验证器
我需要验证器实现的结果。
如果Validator已经开始执行操作(if IsValid =false),我需要在条件下编写它
已经尝试过:
if (CheckAge_CustomValidator.IsValid == false) //if started, and shows an error
{
//actions
}发布于 2016-12-09 09:58:38
如果您想在回发时这样做,请添加Page.Validate("GroupName"),然后检查Page.IsValid。
不过,我不太明白您为什么要这样做,而不是验证客户端?
我宁愿创建一个处理//conditions的方法,而不是自定义验证器。
发布于 2016-12-09 09:00:00
在asp.net页面上,我们可以调用自定义验证器。
<asp:CustomValidator runat="server" id="cusCustom" controltovalidate="txtCustom" onservervalidate="CheckAge_ServerValidate" errormessage="The text must be exactly 8 characters long!" />发布于 2016-12-09 09:13:50
您可以使用Page.Validate或<customValidatorId>.Validate();
https://stackoverflow.com/questions/41056499
复制相似问题