简体   繁体   中英

Two Validation Groups in a Rad Wizard Control

I have a "RadWizard" control (from Telerik) with two "RadWizardSteps" and two different "ValidationGroups".

When I click the first button (BtnArrayAdd), the validation for the "TxtArrayName" control works correct.

When I click the second button (BtnAdd), the validation checks only the "TxtAttributeName" control but not the "CbAttributeType" control.

When I remove the first step, the validation for both controls (TxtAttributeName & CbAttributeType) works correct.

What could be the problem?

Thx, Dominik

<telerik:RadWizardStep ID="StepWebServiceOutArrays" runat="server" StepType="Auto">
                <br />
                <div class="sbLabel1"><asp:Label ID="LblArrayName" runat="server"></asp:Label></div>
                <div class="sbControl1"><telerik:RadTextBox ID="TxtArrayName" runat="server" Width="200"></telerik:RadTextBox></div>
                <div class="sbLabel2"><asp:RequiredFieldValidator ID="TxtArrayNameValidator" runat="server" ControlToValidate="TxtArrayName" ValidationGroup="ArrayValidation" EnableClientScript="true" ForeColor="Red" ></asp:RequiredFieldValidator></div>
                <br /><br /><br />
                <telerik:RadButton ID="BtnArrayAdd" runat="server" CssClass="system" Width="100" OnClick="E_Click" ValidationGroup="ArrayValidation"></telerik:RadButton>
                <telerik:RadButton ID="BtnArrayRemove" runat="server" CssClass="system" Width="100" OnClick="E_Click" CausesValidation="false"></telerik:RadButton>
                <br />
            </telerik:RadWizardStep>

            <telerik:RadWizardStep ID="StepWebServiceOutAttributes" runat="server" StepType="Auto">
                <br />
                <div class="sbLabel1"><asp:Label ID="LblAttributeName" runat="server"></asp:Label></div>
                <div class="sbControl1"><telerik:RadTextBox ID="TxtAttributeName" runat="server" Width="200"></telerik:RadTextBox></div>
                <div class="sbLabel2"><asp:RequiredFieldValidator ID="TxtAttributeNameValidator" runat="server" ControlToValidate="TxtAttributeName" ValidationGroup="AttributeValidation" EnableClientScript="true" ForeColor="Red" ></asp:RequiredFieldValidator></div>
                <br /><br />
                <div class="sbLabel1"><asp:Label ID="LblAttributeType" runat="server"></asp:Label></div>
                <div class="sbControl1"><telerik:RadComboBox ID="CbAttributeType" runat="server" Width="200"></telerik:RadComboBox></div>
                <div class="sbLabel2"><asp:RequiredFieldValidator ID="CbAttributeTypeValidator" runat="server" ControlToValidate="CbAttributeType" ValidationGroup="AttributeValidation" EnableClientScript="true" ForeColor="Red"></asp:RequiredFieldValidator></div>
                <br /><br /><br />
                <telerik:RadButton ID="BtnAdd" runat="server" CssClass="system" Width="100" OnClick="E_Click" ValidationGroup="AttributeValidation"></telerik:RadButton>
                <telerik:RadButton ID="BtnRemove" runat="server" CssClass="system" Width="100" OnClick="E_Click" CausesValidation="false"></telerik:RadButton>
                <br />
            </telerik:RadWizardStep>

There are two possibilities with your code that are causing this issue. These are explained as below.

  • When using a RequiredFieldValidator for radcombobox, you must keep in mind that the text part of selected item in radcombobox is being validated. So, looking at your markup for RequiredFieldValidator , it will only work if the text part of default selected item in radcombobox is an empty string. So, make sure the default item has its text set to empty string.
  • If the text part of default item in radcombobox is not an empty string but something like Select a Type then all you need to do is set InitialValue property of your validator as in following markup.

Markup when default item has non-empty text

<asp:RequiredFieldValidator ID="CbAttributeTypeValidator" runat="server" 
      ControlToValidate="CbAttributeType" ValidationGroup="AttributeValidation"
      EnableClientScript="true" ForeColor="Red"
      InitialValue="Select a type"></asp:RequiredFieldValidator>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM