Required field validator to RadComboBox

9 posts, 1 answers
  1. vvvv
    vvvv avatar
    25 posts
    Member since:
    Aug 2011

    Posted 22 Jan 2014 Link to this post

    I am trying to add a required field validation to a RadComboBox which is defined in a .ascx file. I am using this combo box in many pages. So I wont be able to give required field validation in .ascx page. I have referenced this page in a .aspx page and used a drop down to load with list of combo box items Which works fine. If I add this required field validator I get this error saying
    "Unable to find control id 'radcmbEmployeeSearch' referenced by the 'ControlToValidate' property of 'eventAdminRequired'".

    I tried replacing the controltovalidate with eventAdminDropDown. I get error for this too. Don't know where I am going wrong.
    Any help is much appreciated. 






    <telerik:RadComboBox ID="radcmbEmployeeSearch" runat="server" EmptyMessage="Select Event Admin" AllowCustomText="true"
                         EnableLoadOnDemand="true" ShowMoreResultsBox="true" EnableVirtualScrolling="true" OnItemsRequested="radcmbEmployeeSearch_ItemsRequested" Height="200px">
    </telerik:RadComboBox>
     
     
    <td runat="server">
                    <EAdm:DropDown runat="server" ID="eventAdminDropDown" />
                    <asp:requiredfieldvalidator id="eventAdminRequired" runat="server" display="Dynamic"
                            controltovalidate="radcmbEmployeeSearch" initialvalue="0" enableclientscript="True" errormessage="Required">
                    </asp:requiredfieldvalidator> 
    </td>
    Thanks
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 23 Jan 2014 Link to this post

    Hi,

    Please try to make the RadComboBox with a public property in your UserControl Page as follows.

    C#:
    public RadComboBox DropDownToValidate
    {
        get
        {
            return radcmbEmployeeSearch;
        }
    }

    Then use the UniqueID of the RadComboBox  to set the ControlToValidate in the Page_Load event of the ASPX page where you use the UserControlPage.

    C#:
    protected void Page_Load(object sender, EventArgs e)
    {
        eventAdminRequired.ControlToValidate = WebUserControl31.DropDownToValidate.UniqueID;
    }

    Hope this will helps you.
    Thanks,
    Princy.
  3. vvvv
    vvvv avatar
    25 posts
    Member since:
    Aug 2011

    Posted 23 Jan 2014 Link to this post

    Thanks for the reply Princy.
    So webusercontrol31 refers to the ID of the RadComboBox in ascx page? correct me if I am wrong  because I tried 

    eventAdminRequired.ControlToValidate = eventAdminDropDown.DropDownToValidate.UniqueID; - > error ->

    Unable to find control id 'radcmbEmployeeSearch' referenced by the 'ControlToValidate' property of 'eventAdminRequired'.

    eventAdminRequired.ControlToValidate = radcmbEmployeeSearch.DropDownToValidate.UniqueID; -> doesnt recognize "radcmbEmployeeSearch" field.

    Does this statement have to be on the page load? because I want the validation to work on submit of the page.

    eventAdminRequired.ControlToValidate = WebUserControl31.DropDownToValidate.UniqueID;
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 23 Jan 2014 Link to this post

    Hi,

    yes, 'WebUserControl31' is the ID of the RadComboBox ASCXpage. In order to work RequiredFieldValidator you need to set the ControlToValidate property in either ASPX or Page_Load(). So please try tho set the ControlToValidate property in Page_Load(), and it will do the validation on the Button Click. Please have a look into the sample code snippet which works fine at my end.

    ASPX:
    <uc1:WebUserControl3 ID="WebUserControl31" runat="server" />
    <asp:RequiredFieldValidator ID="eventAdminRequired" runat="server" ValidationGroup="Group1"
        ErrorMessage="*">
    </asp:RequiredFieldValidator>
    <telerik:RadButton ID="RadButton1" runat="server" Text="Submit" ValidationGroup="Group1">
    </telerik:RadButton>

    ASPX C#:
    protected void Page_Load(object sender, EventArgs e)
    {
        eventAdminRequired.ControlToValidate = WebUserControl31.DropDownToValidate.UniqueID;
    }

    ASCX:
    <telerik:RadComboBox ID="radcmbEmployeeSearch" runat="server" EmptyMessage="select">
        <Items>
            <telerik:RadComboBoxItem Text="Item1" />
            <telerik:RadComboBoxItem Text="Item2" />
            <telerik:RadComboBoxItem Text="Item3" />
            <telerik:RadComboBoxItem Text="Item4" />
        </Items>
    </telerik:RadComboBox>

    ASCX C#:
    public RadComboBox DropDownToValidate
    {
        get
        {
            return radcmbEmployeeSearch;
        }
    }

    Thanks,
    Princy.
  5. vvvv
    vvvv avatar
    25 posts
    Member since:
    Aug 2011

    Posted 24 Jan 2014 Link to this post

    I tried the exact same way you followed and I get the following error Princy.
    Unable to find control id 'ctl00$ctl00$ContentPlaceHolder1$mainContent$body$radcmbEmployeeSearch$radcmbEmployeeSearch' referenced by the 'ControlToValidate' property of 'eventAdminRequired'.
    Here is the code at my end.
    .ASCX
    -------
    <telerik:RadComboBox ID="radcmbEmployeeSearch" runat="server" EmptyMessage="Select Event Admin" AllowCustomText="true"
                         EnableLoadOnDemand="true" ShowMoreResultsBox="true" EnableVirtualScrolling="true" OnItemsRequested="radcmbEmployeeSearch_ItemsRequested" Height="200px">
    </telerik:RadComboBox>
     
    .ASCX.CS
    ----------
     public RadComboBox DropDownToValidate
            {
                get
                {
                    return radcmbEmployeeSearch;
                }
            }
     
    .ASPX
    -------
    <%@ Register Src="~/UserControls/EventAdminDropDown.ascx" TagPrefix="EAdm" TagName="DropDown" %>
     
    <tr runat="server">
                <td>
                    Event Admin<span class="Required">*</span>
                </td>
                <td runat="server">
                    <EAdm:DropDown runat="server" ID="radcmbEmployeeSearch" />
                     <asp:RequiredFieldValidator id="eventAdminRequired" runat="server"
                         errormessage="Required" validationgroup="group1">
                    </asp:RequiredFieldValidator>    
    </td>
    </tr>
    <asp:button id="btnCreate" runat="server" text="Create Event" onclick="btnCreateEvent_Click" validationgroup="group1" />
     
    .ASPX.CS
    ---------
     protected void Page_Load(object sender, EventArgs e)
            {
    eventAdminRequired.ControlToValidate = radcmbEmployeeSearch.DropDownToValidate.UniqueID;
    }

    I am stuck with this for so long. Could this be handled in any other way?? I really appreciate your help. 
  6. vvvv
    vvvv avatar
    25 posts
    Member since:
    Aug 2011

    Posted 27 Jan 2014 in reply to vvvv Link to this post

    I need your help guys..Please let me know what I am doing wrong or any work around for this problem...
  7. Answer
    Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    2035 posts

    Posted 29 Jan 2014 Link to this post

    Hello,

    Please find attached a sample project that implements the approach that Princy posted in the very last response. The RadComboBox control is set as public property of the user control so it could be retrieved  from the page that contains this user control.


    Regards,
    Boyan Dimitrov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
  8. vvvv
    vvvv avatar
    25 posts
    Member since:
    Aug 2011

    Posted 29 Jan 2014 in reply to Boyan Dimitrov Link to this post

    Thanks for your reply. Where should I look for the attached project?
  9. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    2035 posts

    Posted 31 Jan 2014 Link to this post

    Hello,

    Please find the project as a .zip file attached to my response.


    Regards,
    Boyan Dimitrov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top