我目前正在使用一个 CustomValidator,它使用 JavaScript 来验证其中一个/或文本框中是否有数字。当我满足验证错误时,消息在提交之前不会清除。我该如何解决这个问题,以便像我的其他开箱即用的验证器一样清除它?我正在使用带有 C# 的 ASP.NET。
<script type="text/javascript">
function testnumbers(source, args) {
var s1 = document.getElementById('<%=arubaBox.ClientID%>').value; var s2 = document.getElementById('<%=shipBox.ClientID%>').value;
if (s1 == "" && s2 == "")
args.IsValid = false;
else if (s1 == "" && s2 != "")
args.IsValid = true;
else if (s1 != "" && s2 == "")
args.IsValid = true;
else if (s1 != "" && s2 !== "") args.IsValid = true;
}
</script>
<asp:TextBox ID="aBox" runat="server" MaxLength="7"></asp:TextBox>
<asp:CustomValidator
ID="CustomValidator1" runat="server" ClientValidationFunction="testnumbers"
ErrorMessage="CustomValidator"
ValidationGroup="Contact"
Text=" Please provide A # or Shipping Account #"
CssClass="errormessage"
Display="Dynamic" >
</asp:CustomValidator>
 <asp:RegularExpressionValidator
id="RegularExpressionValidator1"
runat="server"
ErrorMessage="Field not valid!"
ControlToValidate="aBox"
ValidationExpression="[0-9a-zA-Z]{5,}"
ValidationGroup="Contact"
/> 
<asp:RegularExpressionValidator
ID="NumErrAru"
runat="server"
ControlToValidate="aBox"
CssClass="errormessage"
ErrorMessage=" Numbers Only"
ValidationExpression="^[0-9]+$"
ValidationGroup="Contact"
Display="Dynamic"
Text=" Numbers Only">
</asp:RegularExpressionValidator>