Problem with radListBox

5 posts, 0 answers
  1. Prasad
    Prasad avatar
    40 posts
    Member since:
    Sep 2011

    Posted 21 Jan 2013 Link to this post

    Hi,

    My Scenario is , I have a RadList box with Checkboxes="true" property and a button . If user click on button with out check any item from the radList box then I have to show an error message. For this I used Custom Validator function and Specified Same validator Group name for CustomValidator and Button. But this Custom Validator function is executing by check/Uncheck the Items in the RadList Box.

    My Code Snippet is :-

    function Is_Event_selected(sender, args) {

     

    debugger;

     

    var lstbox = $find("lstEvents");

     

    var chkedItems_Count = lstbox.get_checkedItems().length;

    args.IsValid = chkedItems_Count > 0;

    }


    <div>

     

    <asp:CustomValidator ID="CV_lstEvents" runat="server" ValidateEmptyText="true" ClientValidationFunction="Is_Event_selected"

     

    ControlToValidate="lstEvents" ErrorMessage="please Select Items(s)" ValidationGroup="Event_Group_Validation">

     

    </asp:CustomValidator>

     

    <telerik:RadListBox ID="lstEvents" runat="server" Width="100%" MaxHeight="225px"

     

    CheckBoxes="true" AutoPostBack="false" EmptyMessage="Select Event" CausesValidation="false" >

     

    <Items>

     

    <telerik:RadListBoxItem Text="Ajax Controls" Value="0" />

     

    <telerik:RadListBoxItem Text="BI Controls" Value="1" />

     

    <telerik:RadListBoxItem Text="SilverLight" Value="2" />

     

    <telerik:RadListBoxItem Text="KenDo UI" Value="3" />

     

    </Items>

     

    </telerik:RadListBox>

     

    <asp:Button ID="btn" runat="server" ValidationGroup="Event_Group_Validation" />

     

    </div>

  2. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 21 Jan 2013 Link to this post

    Hello,

    <asp:CustomValidator ID="CV_lstEvents" runat="server" ValidateEmptyText="true" ClientValidationFunction="Is_Event_selected"
               ControlToValidate="lstEvents" ErrorMessage="please Select Items(s)" ValidationGroup="Event_Group_Validation">
           </asp:CustomValidator>
           <telerik:RadListBox ID="lstEvents" runat="server" Width="100%" MaxHeight="225px"
               CheckBoxes="true" AutoPostBack="false" EmptyMessage="Select Event" CausesValidation="false">
               <Items>
                   <telerik:RadListBoxItem Text="Ajax Controls" Value="0" />
                   <telerik:RadListBoxItem Text="BI Controls" Value="1" />
                   <telerik:RadListBoxItem Text="SilverLight" Value="2" />
                   <telerik:RadListBoxItem Text="KenDo UI" Value="3" />
               </Items>
           </telerik:RadListBox>
           <asp:Button ID="btn" runat="server" ValidationGroup="Event_Group_Validation" />
    function Is_Event_selected(sender, args) {
     
         
     
        var lstbox = $find("<%=lstEvents.ClientID %>");
        if (lstbox.get_checkedItems().length > 0) {
            args.IsValid = true;
        }
        else {
            args.IsValid = false;
        }
    }


    Thanks,
    Jayesh Goyani
  3. Prasad
    Prasad avatar
    40 posts
    Member since:
    Sep 2011

    Posted 21 Jan 2013 Link to this post

    Jayesh,
        Thanx for ur response. But my problem is JavaScript function is executing if i check an List box item.
        
     Initially check an item and we are getting validation message .

    Regards,
    Prasad
  4. Prasad
    Prasad avatar
    40 posts
    Member since:
    Sep 2011

    Posted 22 Jan 2013 Link to this post

    Jayesh,
        Did u got my problem .. I am not getting any idea for , why customvalidator client side function is executing by checking the listbox items.
    please provide ur suggestions or Comments on this.

    Regards,
    Prasad
  5. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 22 Jan 2013 Link to this post

    Hello,

    Sorry for late reply.

    Please try with below code snippet.

    <asp:CustomValidator ID="CV_lstEvents" runat="server" ValidateEmptyText="true" ControlToValidate="lstEvents"
               ErrorMessage="please Select Items(s)" ValidationGroup="Event_Group_Validation"
               ClientValidationFunction="Is_Event_selected_test">
           </asp:CustomValidator>
           <telerik:RadListBox ID="lstEvents" runat="server" Width="100%" MaxHeight="225px"
               CheckBoxes="true" EmptyMessage="Select Event">
               <Items>
                   <telerik:RadListBoxItem Text="Ajax Controls" Value="0" Checked="true" />
                   <telerik:RadListBoxItem Text="BI Controls" Value="1" />
                   <telerik:RadListBoxItem Text="SilverLight" Value="2" />
                   <telerik:RadListBoxItem Text="KenDo UI" Value="3" />
               </Items>
           </telerik:RadListBox>
           <asp:Button ID="btn" runat="server" ValidationGroup="Event_Group_Validation" OnClientClick="return Is_Event_selected();" />
    function Is_Event_selected() {
     
                 var CV_lstEvents = document.getElementById('CV_lstEvents');
     
                 ValidatorEnable(CV_lstEvents, false);
     
                 var lstbox = $find("<%=lstEvents.ClientID %>");
                 if (lstbox.get_checkedItems().length > 0) {
                     ValidatorEnable(CV_lstEvents, false);
                     return true;
                 }
                 else {
                     ValidatorEnable(CV_lstEvents, true);
                     return false;
                 }
     
             }
     
             function Is_Event_selected_test(sender, args) {
                 args.IsValid = false;
             }


    Thanks,
    Jayesh Goyani
Back to Top