RadComboBox + RequiredFieldValidator How to make it validate on tab

2 posts, 0 answers
  1. Carlo
    Carlo avatar
    11 posts
    Member since:
    Dec 2011

    Posted 06 Oct 2014 Link to this post

    With the Microsoft Validator controls (RequiredFieldValidator in this case) the typical behavior is for validation logic to run when you tab out of the field, or on submit. 

    I have noticed with RadComboBox this is **not** the case, even in your own online demo. Rather, with RCB validation *only* occurs when you attempt to submit. Is there any way to force this to validate on tab out? Typically the field would look something like this in code:

    1.<telerik:RadComboBox ID="rcbPatientMaritalStatus" EmptyMessage="Start typing marital status or select one" MarkFirstMatch="true" TabIndex="8" Width="160" runat="server">
    2.    <Items>
    3.        <telerik:RadComboBoxItem Text="Single" Value="Single" />
    4.        <telerik:RadComboBoxItem Text="Married" Value="Married" />
    5.        <telerik:RadComboBoxItem Text="Other" Value="Other" />
    6.    </Items>
    1.<asp:RequiredFieldValidator ID="rfvPatientMaritalStatus" ControlToValidate="rcbPatientMaritalStatus" ErrorMessage="Marital Status Required" Display="None" Visible="false" runat="server" />
  2. Nencho
    Nencho avatar
    1874 posts

    Posted 08 Oct 2014 Link to this post

    Hello Carlo,

    First, I would suggest you to remove the Visible="false" settings of the RequiredFieldValidator, since in such a manner, the validator is not rendered on the page, and the desired behavior could not be achieved.

    As for the desired functionality, you could use the OnClientBlur client-side event of the RadComboBox and use the  Page_ClientValidate() function, which will trigger all validators on the page. In order to trigger the validation only on the RadComboBox, you would need to relate the control and its validator, using ValidationGroup. Thus, you will be able to point which validation group to trigger in the Page_ClientValidate(). Below you could find the modified code snippet, demonstrating how to achieve the desired functionality :

    // markup
    <telerik:RadComboBox ID="rcbPatientMaritalStatus" EmptyMessage="Start typing marital status or select one"
        MarkFirstMatch="true" TabIndex="8" Width="160" runat="server" OnClientBlur="OnClientBlur" ValidationGroup="test">
            <telerik:RadComboBoxItem Text="Single" Value="Single" />
            <telerik:RadComboBoxItem Text="Married" Value="Married" />
            <telerik:RadComboBoxItem Text="Other" Value="Other" />
    <telerik:RadButton runat="server" OnCheckedChanged="Unnamed_CheckedChanged" ID="btn1"></telerik:RadButton>
    <asp:RequiredFieldValidator ID="rfvPatientMaritalStatus" ControlToValidate="rcbPatientMaritalStatus"
        ErrorMessage="Marital Status Required" runat="server" Display="Dynamic" ValidationGroup="test" />

    <script type="text/javascript">
            function OnClientBlur(sender, args) {


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top