我创建了一个 CustomValidator 控件
public class MyValidator :CustomValidator, IScriptControl {}
并且还创建了等效的客户端脚本。服务器验证工作正常,但是如何连接我的客户端脚本?
渲染后的 JavaScript 看起来像这样
var MyValidator1 = document.all ? document.all["MyValidator1"] : document.getElementById("MyValidator1");
MyValidator1.controltovalidate = "MyField";
MyValidator1.errormessage = "error";
MyValidator1.evaluationfunction = "MyValidatorEvaluateIsValid";
如何覆盖生成的 javascript 以设置评估函数的值?例如
MyValidator1.evaluationfunction = "MyCustomJavascriptFunction";
最佳答案
您可以像这样设置基类的 ClientValidationFunction 属性 -
base.ClientValidationFunction = "MyCustomJavascriptFunction";
所以,它会像这样渲染 -
MyValidator1.evaluationfunction = "MyCustomJavascriptFunction";
您也可以通过设置相同的属性从控件中执行此操作。
编辑:你可以这样做
document.getElementById("<%= ValidatorId %>").evaluationfunction = "MyCustomJavascriptFunction";
关于asp.net - 如何将 javascript 连接到 .Net 中的 CustomValidator 控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/792858/