通过JavaScript定制的校验错误的文字? [英] Custom validator error text through javascript?
问题描述
我要设置通过客户端的JavaScript ASP.net自定义验证错误参数文本。如何通过发送访问它,ARGS参数在我的功能?
I want to set ASP.net custom validator error parameter text through client side javascript. How can access it via sender, args parameters in my function?
推荐答案
所有你需要做的就是定义在<一个回调方法href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator.clientvalidationfunction.aspx\"相对=nofollow>中的CustomValidator定义ClientValidationFunction 属性:
All you need to do is define the callback method in the ClientValidationFunction property of the CustomValidator definition:
<asp:CustomValidator id="CustomValidator1"
...
ClientValidationFunction="ClientValidationFunction" />
您可以再定义一个客户端验证脚本:
You can then define a client side validation script:
<script language="javascript">
function ClientValidationFunction(sender, args){
var valid = false;
// Validation logic..
sender.errormessage = "Validation failed";
args.IsValid = valid;
return;
}
</script>
更新:在发件人变量保存自定义验证控件的引用 - 因为JavaScript是动态类型,我们就可以更新它的 errormessage的
属性直接:
Update: The sender variable holds a reference to the custom validator control - because JavaScript is dynamically typed, we can just update its errormessage
property directly:
sender.errormessage = "This is a new validation message";
这篇关于通过JavaScript定制的校验错误的文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!