我試圖驗證在轉發器中的產品qty文本框中輸入了某個產品的某個增量。問題是每個產品的增量都不一樣,所以我需要它作爲每個調用的變量來驗證它(我認爲您不能使用自定義驗證程序),並且我需要使用ValidatorCalloutExtender 。我提出的最佳解決方案是觸發一個RegEx驗證器,通過我自己的javascript評估false(另一個驗證器負責確保其有效數字)。問題是,使用ValidatorCalloutExtender,當我禁用驗證器時,它仍然將其標記爲無效(文本框閃爍白色,然後再次變爲黃色(即無效),即使我放置了JavaScript警報,但我知道驗證器正在禁用。有任何想法,以什麼怎麼回事下面是代碼謝謝禁用驗證程序但驗證程序標註仍顯示並導致驗證
PS:?!一切正常瓦特/出validatorCalloutExtender,但我真的需要標註擴展
的驗證:
<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>
數據綁定產品時:
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:對於ValidatorCalloutExtender
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;
}
}
我將文本框的CSS類設置爲javascript函數中的空白並隱藏了標註,所以現在可以使用,但是在框上設置焦點時,它會調用驗證並嘗試針對RegEx驗證程序的^ triggerthisvalidation $表達式進行驗證。我如何使它不會觸發驗證焦點? – Ryan 2009-06-26 16:56:32