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

Problem with radListBox

4 Answers 85 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Prasad
Top achievements
Rank 1
Prasad asked on 21 Jan 2013, 12:02 PM
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>

4 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 21 Jan 2013, 01:04 PM
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
0
Prasad
Top achievements
Rank 1
answered on 21 Jan 2013, 02:06 PM
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
0
Prasad
Top achievements
Rank 1
answered on 22 Jan 2013, 11:27 AM
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
0
Jayesh Goyani
Top achievements
Rank 2
answered on 23 Jan 2013, 03:48 AM
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
Tags
General Discussions
Asked by
Prasad
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Prasad
Top achievements
Rank 1
Share this question
or