2013-03-05 46 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