I'm trying to validate that a certain increment of a product was entered in the product qty textbox that is in a repeater. The problem is that the increment is different for every product, so I need that as a variable for each call to validate it (which I don't think you can do with a custom validator), and I need it client side with a ValidatorCalloutExtender. The best solution i have come up with is to trigger a RegEx validator that will evaluate false via my own javascript (another validator takes care of making sure its a valid number). The problem is that with the ValidatorCalloutExtender, when I disable the validator it still marks it as invalid (the textbox flashes white then turns yellow again (meaning its invalid), even though I placed JavaScript alerts and I know the validator is getting disabled. Anyone have any ideas as to whats going on here? Here is the code. Thanks!
PS: Everything works fine w/out the validatorCalloutExtender, but I really need the Callout Extender!
The 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 Databinding the 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 & "')")
The 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;
}
}