【问题标题】:change customvalidator message dynamically in clientside在客户端动态更改自定义验证消息
【发布时间】:2013-03-05 09:58:41
【问题描述】:

我想通过 ClientValidationFunction 在客户端动态更改 customvalidator 消息。在 java 脚本中我有:

function valnationalid(source, arguments) {     
    if (arguments.Value == ""){         
        source.errormessage = "custom message here";
        arguments.IsValid = false;
    } else if (arguments.Value == "Something else"){
        source.errormessage = "another custom message here";
        arguments.IsValid = false;
    }
}

在正文中:

<input runat="server" id="txtnationalid" maxLength="10" name="txtnationalid" class='person ltr glow-onfocus customerCode required number' dir="ltr" />
<asp:CustomValidator ID="valnationalid1" runat="server" EnableClientScript="true" ClientValidationFunction="valnationalid"  ValidateEmptyText="True" Display="Dynamic" ControlToValidate="txtnationalid"> </asp:CustomValidator>                            

但我的页面中没有显示任何消息。

【问题讨论】:

  • 你的 JS 是否执行。还有你想做什么,你的验证器总是返回 false。
  • 是的。我通过在“if-else”结构中扭动警报(STH.)来测试它,它出现在我的屏幕上。

标签: jquery asp.net validation


【解决方案1】:

以下对我有用:

替换

source.errormessage = "custom message here";

source.innerHTML = "custom message here";

【讨论】:

  • 我做到了,杰克,但它仍然不起作用。我什至删除了 IF-Else,只写了这个:'function valnationalid(source, arguments) { source.errormessage = "custom message here";参数.IsValid = false; }' 但它不起作用。
  • 杰克,有趣的是,当我在 if 或 else 部分的末尾添加 alert("hi") 时,它可以工作并且 hi 显示在屏幕上。
  • @Farhad,我已经编辑了我的答案,请尝试source.innerHTML。我还删除了我要求您所做的更改,因为您已在问题中实施了这些更改
猜你喜欢
  • 1970-01-01
  • 2012-01-21
  • 2012-11-08
  • 1970-01-01
  • 2017-04-12
  • 2016-08-25
  • 2017-12-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多