【问题标题】:asp.net custom validator not firing.asp.net 自定义验证器未触发。
【发布时间】:2015-03-18 15:23:47
【问题描述】:
<script type="text/javascript">
function ValidateProductID(sender, args)
{
    var productID = document.getElementById('<%=txtProductID.ClientID%>').value;
    var productType = document.getElementById('<%=rcbProduct.ClientID%>').value;

    if (productID != "" && productID == "") {
        args.isValid = false;
    }
}

我有这个自定义验证来验证 2 个控件,如果输入了 productID,则应该选择 ProductType。

这是aspx代码

 <asp:CustomValidator ID="CustomValidator1" runat="server" EnableClientScript="true" 
                                                       ErrorMessage="please select a Product" 
                                                       ClientValidationFunction="ValidateProductID"
                                                       ControlToValidate ="txtProductID"
                                                       Display = "Dynamic">
                                  </asp:CustomValidator>

事件没有触发,我错过了什么吗??

【问题讨论】:

  • 您是否错过了验证组?
  • 您是如何创建txtProductID 控件和提交/操作按钮的?
  • ''

标签: asp.net customvalidator


【解决方案1】:
if (productID != "" && productID == "")

错了(错字)应该是

 if (productID != "" && productType == "")

【讨论】:

    【解决方案2】:

    您可以将 ControlToValidate 留空。

    与所有其他验证控件一样(除了 RequiredFieldValidator),如果输入字段为 空白。

    https://msdn.microsoft.com/en-us/library/aa479045.aspx

    【讨论】:

      猜你喜欢
      • 2011-08-06
      • 2011-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-13
      • 2010-10-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多