validation on Radlistbox

5 posts, 0 answers
  1. Rahul
    Rahul avatar
    39 posts
    Member since:
    Jan 2014

    Posted 08 Jan 2014 Link to this post

    Hi,
                      validation on Radlistbox and if list box checkbox not checked show error message on button click.

    Thanks,
    Rahul
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 08 Jan 2014 Link to this post

    Hi Rahul,

    Please have a look into the following code snippet to achieve your scenario.

    ASPX:
    <telerik:RadListBox runat="server" ID="RadListBox1" CheckBoxes="true" Height="200px"
        Width="230px">
        <Items>
            <telerik:RadListBoxItem Text="Item1" runat="server" />
            <telerik:RadListBoxItem Text="Item2" runat="server" />
            <telerik:RadListBoxItem Text="Item3" runat="server" />
            <telerik:RadListBoxItem Text="Item4" runat="server" />
        </Items>
    </telerik:RadListBox>
    <asp:CustomValidator ID="CustomValidator2" runat="server" ClientValidationFunction="ValidationCriteria"
        ErrorMessage="CustomValidator">
    </asp:CustomValidator>
    <telerik:RadButton ID="RadButton1" runat="server" Text="Validate" AutoPostBack="false">
    </telerik:RadButton>

    JavaScript:
    <script type="text/javascript">
        function ValidationCriteria(source, args) {
            var listbox = $find('<%= RadListBox1.ClientID %>');
            if (listbox.get_checkedItems().length == listbox.get_items().get_count())
                args.IsValid = true;
            else
                args.IsValid = false;
        }
    </script>

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Aneliya Petkova
    Admin
    Aneliya Petkova avatar
    207 posts

    Posted 08 Jan 2014 Link to this post

    Hello Rahul, 

    Thank you for contacting us.

    To assist you the most efficient way in resolving the issue that you are currently experiencing, can you please provide me with a very simplified runnable project that I can test from my side and observe the issue that you have? Can you also explain in more details the exact issue - what is the current behavior, what is the expected one, under which browsers is reproducible?

    We will be waiting for your reply.

    Regards,
    Aneliya Petkova
    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 RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  5. Rahul
    Rahul avatar
    39 posts
    Member since:
    Jan 2014

    Posted 11 Jan 2014 Link to this post

    my code is
    <telerik:RadListView runat="server"  ID="RadListView1" onitemdatabound="RadListView1_ItemDataBound" BorderColor="White" BorderStyle="None">
                                                                <ClientSettings></ClientSettings>
                                                                <ItemTemplate>
                                                                   <div>
                                                                   <table>
                                                                         <tr>
                                                                            <td class="LabelWidth">
                                                                                <asp:Label ID="Label4" runat="server" Text='<%# (DataBinder.Eval(Container.DataItem,"PermissionItemName")) %>'></asp:Label>
                                                                            </td>
                                                                           
                                                                            <td>
                                                                                <asp:CheckBoxList RepeatDirection="Horizontal" CssClass="horizontalListbox" ID="Listbox_Permission" runat="server" S>
                                                                                </asp:CheckBoxList>
                                                                                <%--DataTextField="PermissionOperationName"--%>
                                                                            </td>
                                                                        </tr>                                         
                                                                  </table>
                                                                 </div>
                                                              </ItemTemplate>
                                                         </telerik:RadListView>
                                                         <telerik:RadListBox ID="qw" runat="server" CheckBoxes="True" BorderColor="White" BorderStyle="None" DataValueField="PermissionItemOpearationId" 
                                                                                         DataTextField="PermissionOperationName"  BorderWidth="0" AutoPostBack="false" CssClass="horizontalListbox" CausesValidation="false" ></telerik:RadListBox>
                                                                                        
                                                          <asp:CustomValidator ID="custm_vldator_role" runat="server" ClientValidationFunction="ValidateRadlistbox" ErrorMessage="Should select atleast One"  ForeColor="Red" >*</asp:CustomValidator>

    <asp:Button ID="btn_new" CssClass="btn btn-sm btn-success" runat="server" Text="Submit"  onclick="btn_new_Click" ValidationGroup="role" />
    

  6. Aneliya Petkova
    Admin
    Aneliya Petkova avatar
    207 posts

    Posted 13 Jan 2014 Link to this post

    Hi Rahul,

    Unfortunately without being able to test the actual project locally, It is indeed very hard to determine what might be causing the issue (you have not send us your exact code – “ValidateRadlistbox”, “btn_new_Click”, “RadListView1_ItemDataBound” functions). However, I have tried to modify your .aspx, but I am currently not able to replicate the issue from my side.

    Did you review the
    code snippet provided by Shinu? Does it work at your side?
    Could you please send us your exact functions or modify the Shinu's code so we can see the problem locally and assist you in most efficient way in resolving the issue. 

    Regards,
    Aneliya Petkova
    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 RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017