在CompareValidator上添加JS验证
是否可以为CompareValidator添加JS验证功能?
我无法使用 CustomValidator。
is it possible to add a JS validation function for CompareValidator?
i can't use a CustomValidator.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您是否仍然需要它,但我认为不需要,因为这是没有答案的...
好吧,您不能直接执行此操作,但是您可以隐藏负责 CompareValidator 验证的原始函数并引入新的函数。这是可能的,因为所有验证函数都来自全局范围内的 ASP.NET,这是有争议的,但在这种情况下很有帮助。
请找到以下模块来完成工作。它向您展示了两种方法。第一个称为 addFunction 允许您添加一个或多个函数以进行自定义验证。此函数应返回 Boolean 并分别使用三个参数 Validator object 、 TargetObject 和 CompareObject 。第二个名为 disableOldFunction 的函数允许您完全摆脱旧的验证函数,如果您的所有函数都有效,则该函数将由模块调用。
用法示例:
警告:请将此模块放置在页面底部的某个位置,以确保默认验证脚本已就位。您还可以稍微重写模块以推迟初始化,直到文档准备好为止。
I'm not sure whether you still need it or not, I assume not however since this is unanswered...
Well, you can't do it directly, however you can hide original function which is responsible for CompareValidator validation and introduce new one. This is possible because all validation functions comes from ASP.NET in global scope which is... controversial, but helpful in that case.
Please find following module which get the job done. It exposes you two methods. First called addFunction allows you to add one or more functions for custom validation. This function should returns Boolean and it consumes three parameters Validator object , TargetObject and CompareObject respectively. Second one called disableOldFunction allows you to completely get rid of old validation function which is called by the module if all your functions are valid.
Example usage:
Caveat: Please place this module somewhere on the page bottom to be sure that default validation scripts are in place already. You can also rewrite module a bit to defer initialization until document will be ready.