您可以为标准 ASP.NET Web 表单验证器自定义客户端 javascript 验证吗? [英] Can you have custom client-side javascript Validation for standard ASP.NET Web Form Validators?

查看:19
本文介绍了您可以为标准 ASP.NET Web 表单验证器自定义客户端 javascript 验证吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能否为标准 ASP.NET Web 表单验证器自定义客户端 javascript 验证?

Can you have custom client-side javascript Validation for standard ASP.NET Web Form Validators?

例如使用 asp:RequiredFieldValidator 保留服务器端代码,但使用 jQuery 实现您自己的客户端通知以突出显示字段或背景颜色.

For instance use a asp:RequiredFieldValidator leave the server side code alone but implement your own client notification using jQuery to highlight the field or background color for example.

推荐答案

标准 CustomValidator 有一个 ClientValidationFunction 属性:

The standard CustomValidator has a ClientValidationFunction property for that:

<asp:CustomValidator ControlToValidate="Text1" 
                     ClientValidationFunction="onValidate" />

<script type='text/javascript'>
function onValidate(validatorSpan, eventArgs)
 { eventArgs.IsValid = (eventArgs.Value.length > 0);
   if (!eventArgs.IsValid) highlight(validatorSpan);
 }
</script>

这篇关于您可以为标准 ASP.NET Web 表单验证器自定义客户端 javascript 验证吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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