我的页面上有许多不同类型的ASP.NET验证器,根据用户在页面上的选择,我使用javascript禁用了其中一些验证器。
$.each(Page_Validators, function(index, validator)
{
if ($(validator).hasClass("pain")) {
ValidatorEnable(validator, false);
}
});这似乎是有效的,并且验证器并不是在所有情况下都会触发,除了当我不能使用其他验证器类型时使用的任何CustomValidators
<asp:CheckBoxList id="BodyPartsList" runat="server" RepeatColumns = "2"
Width="1023px">
<asp:ListItem Text = "0. Head/headaches" Value = "1"></asp:ListItem>
<asp:ListItem Text = "1. Leg(s)" Value = "2"></asp:ListItem>
<asp:ListItem Text = "2. Arm(s)" Value = "3"></asp:ListItem>
<asp:ListItem Text = "3. Neck" Value = "4"></asp:ListItem>
<asp:ListItem Text = "4. Shoulder(s)" Value = "5"></asp:ListItem>
<asp:ListItem Text = "5. Low Back" Value = "6"></asp:ListItem>
<asp:ListItem Text = "6. Upper Back" Value = "7"></asp:ListItem>
<asp:ListItem Text = "7. Feet" Value = "8"></asp:ListItem>
<asp:ListItem Text = "8. Hand(s)" Value = "9"></asp:ListItem>
<asp:ListItem Text = "9. Other(Describe in "Details of Plan")" Value = "10"></asp:ListItem>
</asp:CheckBoxList>
<asp:CustomValidator ID="PainLocationValidator" runat="server" Display="Dynamic"
ErrorMessage="Location of pain is required."
ClientValidationFunction="checkPainListValidate"
ValidationGroup = "OnSave" EnableClientScript= "true" SetFocusOnError= "true" Width = "100%" CssClass = "pain" />
function checkPainListValidate(sender, args) {
args.IsValid = true;
if ($('#<%= BodyPartsList.ClientID %> input:checked').length > 0)
args.IsValid = true;
else
args.IsValid = false;
}为什么会发生这种情况?我还能做些什么来禁用它们吗?
谢谢。
发布于 2011-02-09 06:03:57
一些aspx标记可能会有所帮助,但不管怎样,这里有一些想法:
validatorEnable而不是ValidatorEnable?您是否收到任何CustomValidator错误?EnableClientScript设置为true我假设您在客户端使用了错误的ID来获取验证器。
我已经测试了你的代码,不能重现这个行为:
这是我的Javascript-禁用所有验证器的函数(编辑后将pain-class考虑在内):
function disablePainValidators() {
if ((typeof (Page_Validators) != "undefined") && (Page_Validators != null)) {
var i;
for (i = 0; i < Page_Validators.length; i++) {
if(Page_Validators[i].className=='pain')
ValidatorEnable(Page_Validators[i], false);
}
}
}https://stackoverflow.com/questions/4938807
复制相似问题