通过Javascript验证消息

时间:2012-03-30 01:49:34

标签: c# javascript asp.net validation devexpress

我在这里有一个问题。选中复选框时如何禁用验证。我试过ValidatorEnable(控制,假),它不适合我。

<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('');
    }
}

感谢您的建议。

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

正如我从您的问题中发现的那样,您正在寻找小组验证:

首先在ValidationSettings中设置ValidateOnLeave =“False”并为控件指定验证组名称,然后使用客户端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

相关问题