2013-03-05 50 views
0

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

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>        

但没有消息显示在我的网页。

+0

贵JS执行的。还有你想做什么,你的验证器总是会返回false。 – 2013-03-05 10:05:27

+0

是的。我在“if-else”结构中通过扭动警报(STH)对其进行测试,并且它出现在我的屏幕中。 – Farhad 2013-03-05 10:16:53

回答

0

对我来说,以下工作:

更换

source.errormessage = "custom message here"; 

随着

source.innerHTML = "custom message here"; 
+0

Thanks.But它不适合我。 – Farhad 2013-03-05 12:00:28

+0

我做到了杰克,但它仍然无法工作。我甚至删除的if-else,只是这样写: “功能valnationalid(来源参数){\t \t \t \t \t \t source.errormessage = “这里自定义消息”; \t \t \t arguments.IsValid = false; \t \t \t \t}' 但它不起作用。 – Farhad 2013-03-05 12:40:14

+0

我尝试了他们两个,但不幸的是它还没有工作。 – Farhad 2013-03-05 13:10:51