2012-03-30 71 views
1

我在這裏有一個問題。如何在複選框選中時禁用驗證。我曾嘗試ValidatorEnable(控制,錯誤),它不能爲我工作。通過Javascript發送有效信息

<dxe:BaseCheckBox runat ="server" ID="chkIsChecked" ClientInstanceName ="chkIsChecked"> 
     <ClientSideEvents CheckedChanged="OnSelectionChanged"/> 
</dxe:BaseCheckBox> 


<dxe:BaseComboBox runat ="server" ID="cboLabour" ClientInstanceName ="cboLabour" ValueType="System.String" ClientEnabled="false" > 
    <ValidationSettings SetFocusOnError="True" ErrorText="This field is required to fill." 
     ErrorDisplayMode="ImageWithTooltip" ValidationGroup="RejectReason" 
     CausesValidation="false"> 
      <RequiredField IsRequired="True" ErrorText="This field is required to fill."> 
      </RequiredField> 
    </ValidationSettings> 
</dxe:BaseComboBox> 

我的javascript:

function OnSelectionChanged(s,e) 
{ 
    if(chkIsChecked.GetValue()) 
    { 
     cboLabour.SetEnabled(true); 
    } 
    else 
    {  
     cboLabour.SetEnabled(false); 
     cboLabour.SetValue(''); 
    } 
} 

感謝的建議。

+1

既然你不使用內置控件,您應該指定這些都是從哪個庫。答案取決於它。 – 2012-03-30 03:05:44

+0

Devexpress 8.1你的意思是? – 2012-04-02 06:54:41

回答

0

要做到這一點,你需要使用自定義驗證。事情是這樣的:

function OnLabouryValidation(s, e) { 
    if (chkIsChecked.GetValue()) 
     return; 

    var v = e.value; 
    if(e.value) 
      return; 

    e.isValid = false; 
    e.errorText = "Required."; 
} 

有一個關於自定義驗證「文檔」在這裏,但在我的快速閱讀,它不是明確清楚如何這樣組裝起來。

http://documentation.devexpress.com/#AspNet/CustomDocument11135

+0

謝謝,看着它。 – 2012-03-30 03:36:36

0

正如我從你的問題發現你正在尋找的羣驗證:

第一套ValidationSettings的ValidateOnLeave =「假」,並指定驗證組的名稱,以您的控件,然後使用客戶端ASPxClientEdit.ValidateGroup('MyGroup');方法通過根據您的需求進行一些定製來驗證您的控件組。

標記:

<dxe:BaseCheckBox runat ="server" ID="chkIsChecked" ClientInstanceName ="chkIsChecked"> 
      <ClientSideEvents CheckedChanged="OnSelectionChanged"/> 
    </dxe:BaseCheckBox> 


    <dxe:BaseComboBox runat ="server" ID="cboLabour" ClientInstanceName ="cboLabour" ValueType="System.String" ClientEnabled="false" > 
     <ValidationSettings SetFocusOnError="True" ErrorText="This field is required to fill." 
      ErrorDisplayMode="ImageWithTooltip" ValidationGroup="RejectReason" 
      ValidateOnLeave="False"> 
       <RequiredField IsRequired="True" ErrorText="This field is required to fill."> 
       </RequiredField> 
     </ValidationSettings> 
    </dxe:BaseComboBox> 


<dx:ASPxButton ID="btn" runat="server" Text="Validate" 
AutoPostBack="False" CausesValidation="False"> 

     <ClientSideEvents Click="function(s, e) { 

    if (chkIsChecked.GetValue()) // if checked then validate the group 
    { 
       ASPxClientEdit.ValidateGroup('RejectReason'); 
    } 
     }" /> 
    </dx:ASPxButton> 

按照這些文件並執行任何你正在嘗試做的。
How to: Validate a Group of Editors
How to: Validate All Editors on a Page
How to: Implement a Custom Validation
ASPxClientEdit.Validation Event

+0

我在btn中添加了按鈕點擊事件,它是OnClick =「btnSubmit_Click」,當我點擊按鈕後,頁面成功驗證了組合框,但它會觸發btnSubmit_click事件。 – 2012-04-02 06:24:23

+0

你用過AutoPostBack =「False」它會停止回發 – 2012-04-02 07:54:48