This is a migrated thread and some comments may be shown as answers.

validation on Radlistbox

4 Answers 176 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Rahul
Top achievements
Rank 1
Rahul asked on 08 Jan 2014, 07:01 AM
Hi,
                  validation on Radlistbox and if list box checkbox not checked show error message on button click.

Thanks,
Rahul

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 08 Jan 2014, 09:33 AM
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.
0
Aneliya Petkova
Telerik team
answered on 08 Jan 2014, 12:19 PM

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.
0
Rahul
Top achievements
Rank 1
answered on 11 Jan 2014, 10:13 AM
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" />

0
Aneliya Petkova
Telerik team
answered on 13 Jan 2014, 09:46 AM

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.
Tags
ListBox
Asked by
Rahul
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Aneliya Petkova
Telerik team
Rahul
Top achievements
Rank 1
Share this question
or