CustomValidator 的 ClientValidationFunction 在设置 args.IsValid true/false 时失败
我有一个带有 ClientValidationFunction 的 CustomValidator,如下所示,
function checkAmount(source, args) {
var opt = document.getElementById('<%=optByAmount.ClientID %>');
var txt = document.getElementById('<%=txtAmount.ClientID %>');
if (opt.checked == true && txt.value == '') {
//args.IsValid = false;
alert('failed');
}
else {
//args.IsValid = true;
alert('passed');
}
}
仅当注释行被注释时,我才会收到错误消息“通过”和“失败”。当这些线路启用时,我根本没有收到任何警报。为什么 ??
编辑 停止并运行代码 20 分钟(执行这部分代码之外的其他操作)后,它现在可以运行了!谢谢达米安和 ub1k。我永远不会知道为什么会发生:(
I have a CustomValidator with ClientValidationFunction as below
function checkAmount(source, args) {
var opt = document.getElementById('<%=optByAmount.ClientID %>');
var txt = document.getElementById('<%=txtAmount.ClientID %>');
if (opt.checked == true && txt.value == '') {
//args.IsValid = false;
alert('failed');
}
else {
//args.IsValid = true;
alert('passed');
}
}
I receive error messages 'passed' and 'failed' ONLY when the commented lines are COMMENTED. When these lines are enabled, i don't get any alert at all. Why ??
EDIT
After stopping and running the code for 20 minutes (doing something other than this part of the code), It is working now !!! Thanks Damian and ub1k. I would never know why was it happening :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您能否在代码中添加额外的行?
在第一行?
我已经仔细检查了你的代码,它非常适合我。除此之外,我多次使用 CustomValidator,问题可能出在其他地方。现在,如果您可以检查 args 是否存在,那将会很有帮助。
Could you please add additional line to your code?
in the first line?
I have double checked your code and it works perfectly for me. Apart from that I used CustomValidator many times and the problem is probably somewhere else. For now if you could check whether args exist it would be helpful.
最有可能的是因为
抛出异常并且代码执行从那时起就不再执行,
难道 args 不应该以某种方式初始化为数组吗?
Most probably because the
throws an exception and the code execution doesn't follow from then on
shouldn't args be initialized as an array somehow?