asp.net 自定义验证器未触发。
asp.net custom validator not firing.
<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>
活动没有触发,我是不是错过了什么??
if (productID != "" && productID == "")
错了(错字)应该是
if (productID != "" && productType == "")
您可以将 ControlToValidate 留空。
Like all the other validation controls (besides
RequiredFieldValidator), it is considered valid if the input field is
blank.
<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>
活动没有触发,我是不是错过了什么??
if (productID != "" && productID == "")
错了(错字)应该是
if (productID != "" && productType == "")
您可以将 ControlToValidate 留空。
Like all the other validation controls (besides RequiredFieldValidator), it is considered valid if the input field is blank.