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; } }
source share