Add custom validation for RadComboBox with Checkboxes

2 posts, 0 answers
  1. Rajesh
    Rajesh avatar
    6 posts
    Member since:
    Apr 2013

    Posted 13 Nov 2013 Link to this post


    I want to add validation for Radcombobox which contains checkboxes for multiple selection. The issue is the custom validation handler is getting fired on page load. I want to get if fired every time when the user clicks on submit.

    Please find the code below ;

    <telerik:RadComboBox ID="ddlAcc"  runat="server" DataValueField="Value" DataTextField="Text" Width="270" AllowCustomText="true" ExpandDirection="Up"   AutoPostBack="true" Height="150" CausesValidation="true" HighlightTemplatedItems="true" OnItemDataBound="ddlAcc_ItemDataBound" OnSelectedIndexChanged="ddlAcc_SelectedIndexChanged">
                          <asp:CheckBox runat="server"  ID="SelectAll" />
                          <asp:Label runat="server" ID="hdrLabel" Font-Bold="false" AssociatedControlID="SelectAll">Select All</asp:Label>
                          <div onclick="StopPropagation(event)">
                              <asp:CheckBox runat="server" ID="chk1" />
                              <asp:Label runat="server" ID="label1" Font-Bold="false" Font-Size="Smaller" AssociatedControlID="chk1"><%# DataBinder.Eval(Container, "Text") %></asp:Label>
                   <asp:CustomValidator ID="cvAccNos" runat="server" ErrorMessage="<%$ Resources: ErrorMessages, error.missing.accountnumber %>"
                          OnServerValidate="cvAccNos_ServerValidate" ControlToValidate="ddlAcc"
                          Text="<%$ Resources: ErrorMessages, error.validatoricon %>"  EnableClientScript="False" />

    In the code behind :

    protected void cvAccNos_ServerValidate(object sender, ServerValidateEventArgs args)
               args.IsValid = !string.IsNullOrEmpty(GetCheckBoxValues());

    Please help . This is urgent
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 22 Nov 2013 Link to this post

    Hi Rajesh,

    Please have a look into the sample code snippet to call a server side event of a CustomValidator on ButtonClick.

    <telerik:RadComboBox ID="RadComboBox1" runat="server" DataSourceID="SqlDataSource1"
        DataValueField="id" EmptyMessage="Select" DataTextField="text" AutoPostBack="true">
    <asp:CustomValidator ID="CustomValidator1" ValidateEmptyText="true" runat="server"
        ErrorMessage="*" OnServerValidate="CustomValidator1_ServerValidate" ControlToValidate="RadComboBox1"
        Text="*" />
    <br />
    <br />
    <telerik:RadButton ID="RadButton1" runat="server" Text="Submit" CausesValidation="true">

    protected void CustomValidator1_ServerValidate(object sender, ServerValidateEventArgs args)
        string selectedtext = RadComboBox1.Text;
        if (selectedtext == "")
            args.IsValid = false;
            Response.Write("<script>alert('Please select an Item');</script>");
            args.IsValid = true;

  3. DevCraft R3 2016 release webinar banner
Back to Top