使用javascript更改所需的字段验证器错误消息

问题描述 投票:-1回答:2

我有一个必填字段验证器,带有通用错误消息;使用Java脚本,我想根据某些条件更改错误

我正在使用此代码

    var RfvInternalNotes = document.getElementById("RfvInternalNotes");
    RfvInternalNotes.innerText = "";
    RfvInternalNotes.innerText = "Please enter a reason for assigning this question to a different person";

没有JavaScript错误,但未显示我的自定义消息,而是显示了我在必填字段验证器属性中设置的错误消息。我也尝试过此]

RfvInternalNotes.ErrorMessage= "Please enter a reason for assigning this question to a different person";

但没有喜悦;有什么帮助吗?谢谢

javascript c# ajaxcontroltoolkit
2个回答
0
投票

我认为您可以更好地使用Custom Validator并使用其ClientValidationFunction函数,该函数看起来可能像这样:

<asp:CustomValidator id="CustomValidator1" 
          ClientValidationFunction="MyClientValidationFunction" />

<script language="javascript">
      function MyClientValidationFunction(sender, args){

               sender.errormessage = "Validation failed";

               args.IsValid = true; // false based upon your conditions...
               return;        
       }
</script>

Client Validation Function Reference


0
投票

发现问题;我也在其他地方调用了该函数。现在正在工作

© www.soinside.com 2019 - 2024. All rights reserved.