2011-02-08 48 views
0

我在我的各種類型的頁面上有許多ASP.NET驗證器,其中一些我使用javascript取決於頁面上的用戶選擇而禁用。CustomValidator問題

​​

這似乎是工作和驗證器不火,除了任何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 &quot;Details of Plan&quot;)" 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; 

} 

這究竟是爲什麼?還有什麼我可以做的,以禁用這些呢?

謝謝。

回答

0

一些ASPX的標記將是有益的,但無論如何,這裏有一些想法:

  • 有你調試的JavaScript來看看發生了什麼,如果你的驗證爲空,或者您有一種類似的validatorEnable代替ValidatorEnable ?你有任何的JavaScript錯誤?
  • 是否驗證的CustomValidator在服務器或客戶機側上,我認爲ValidatorEnable只會禁用它在客戶方
  • 設置EnableClientScript爲true
  • 如果你不指定的ControlToValidate,該會的CustomValidator驗證在每次回傳,無論導致它的事件
  • 你提供了ClientValidationFunction在客戶端被調用嗎?順便說一下,你使用的瀏覽器和框架是什麼,它是ASP.Net-Ajax嗎?
  • 您是否試圖通過document.getElementById('<%=MyValidator.ClientID %>').disabled=true;禁用它?

我假設你使用錯誤的ID來獲取客戶端的驗證器。

我已經測試你的代碼,並不能重現此問題:

這是我的javascript功能禁用所有驗證(編輯把你的痛苦級考慮在內),

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); 
     } 
    } 
} 
+0

感謝答覆和一些有用的想法1.我沒有想到第一個想法2.我在客戶端驗證它,所以使用ClientValidationFunction,看到更新3.我沒有指定ControlToValidate,因爲它是一個複選框列表,如果我有錯誤去做。 4.如果你禁用驗證器,它會在每次回發中驗證嗎? – Victor 2011-02-08 22:34:03