Disable the validator, but the validator leader still shows and invokes validation

I am trying to verify that a certain amount of a product instance has been entered in the producttyty text box that is in the repeater. The problem is that the increment for each product is different, so I need it as a variable for each call to check it (which I don’t think you can do with a special validator), and I need the client side with ValidatorCalloutExtender, The best solution which I came up with is to run a RegEx validator that will evaluate to false through my own javascript (another validator will take care to make sure it is a valid number). The problem is that with ValidatorCalloutExtender, when I disabled the validator, it is still marked as invalid (the text field blinks white and then turns yellow again (which means it is invalid), although I put JavaScript warnings, and I know that the validator shuts down.I have any idea what is going on here? Here is the code. Thanks!

PS: Everything works fine with validatorCalloutExtender, but I really need an Extender Callout!

Validators:

<asp:RegularExpressionValidator ID="ProductIncrementValidator" runat="server" ControlToValidate="ProductQtyTxt" ErrorMessage="Please enter a valid increment" ValidationExpression="^triggerthisvalidation$" Enabled="false" Display="Dynamic" SetFocusOnError="true" ValidationGroup="productValidation"> </asp:RegularExpressionValidator> <ajax:ValidatorCalloutExtender ID="ProductIncrementVE" runat="server" TargetControlID="ProductIncrementValidator" HighlightCssClass="validator" WarningIconImageUrl="~/img/blank.gif"> </ajax:ValidatorCalloutExtender> 

When binding data to a product:

 Dim productQtyTxt As TextBox productQtyTxt = CType(e.Item.FindControl("ProductQtyTxt"), TextBox) Dim incrementValidator As RegularExpressionValidator incrementValidator = CType(e.Item.FindControl("ProductIncrementValidator"), RegularExpressionValidator) incrementValidator.ErrorMessage = "Please enter an increment of " & product.OrderIncrement.ToString() ' Add item qty increment check productQtyTxt.Attributes.Add("onChange", "javascript:checkIncrement('" _ & productQtyTxt.ClientID & "', " _ & product.OrderIncrement & ", '" _ & incrementValidator.ClientID & "')") 

Javascript:

  function checkIncrement(textboxID, incrementQty, validatorID) { var textbox = $get(textboxID); var incrementValidator = $get(validatorID); var qtyEntered = textbox.value; if ((qtyEntered % incrementQty) != 0) { ValidatorEnable(incrementValidator, true); alert("not valid"); return; } else { ValidatorEnable(incrementValidator, false); alert("valid"); return; } } 
+4
source share
2 answers

I had the same problem, I solved with something like this

 if ((qtyEntered % incrementQty) != 0) { ValidatorEnable(incrementValidator, true); $("#" + validatorID + "_ValidatorCalloutExtender_popupTable").show(); alert("not valid"); return; } else { ValidatorEnable(incrementValidator, false); $("#" + validatorID + "_ValidatorCalloutExtender_popupTable").hide(); alert("valid"); return; } 

Hope this helps someone.

0
source

1. Set CSS class for ValidatorCalloutExtender:

 <style id = "style1" type="text/css"> .CustomValidator { position: relative; margin-left: -80px; margin-top: 8px; display: inherit; } </style>
<style id = "style1" type="text/css"> .CustomValidator { position: relative; margin-left: -80px; margin-top: 8px; display: inherit; } </style> 

 <ajax:ValidatorCalloutExtender ID="ProductIncrementVE" runat="server" TargetControlID="ProductIncrementValidator" HighlightCssClass="validator" WarningIconImageUrl="~/img/blank.gif" CssClass="CustomValidator"> </ajax:ValidatorCalloutExtender>
<ajax:ValidatorCalloutExtender ID="ProductIncrementVE" runat="server" TargetControlID="ProductIncrementValidator" HighlightCssClass="validator" WarningIconImageUrl="~/img/blank.gif" CssClass="CustomValidator"> </ajax:ValidatorCalloutExtender> 

2. Use JavaScript to change this CSS class when necessary. Set display = none:

 function alterDisplay(type) { var styleSheet, cssRule; if (document.styleSheets) { styleSheet = document.styleSheets[index1]; if (styleSheet) { if (styleSheet.cssRules) cssRule = styleSheet.cssRules[index2]; // Firefox else if (styleSheet.rules) cssRule = styleSheet.rules[index2]; // IE if (cssRule) { cssRule.style.display = type; } } } }
function alterDisplay(type) { var styleSheet, cssRule; if (document.styleSheets) { styleSheet = document.styleSheets[index1]; if (styleSheet) { if (styleSheet.cssRules) cssRule = styleSheet.cssRules[index2]; // Firefox else if (styleSheet.rules) cssRule = styleSheet.rules[index2]; // IE if (cssRule) { cssRule.style.display = type; } } } } 

Note. index1 and index2 may differ from pages, it depends on your ad. You can use the IE debugger to find the correct indexes.

+1
source

All Articles