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

facing Problems with RAdList box

1 Answer 28 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Prasad
Top achievements
Rank 1
Prasad asked on 21 Jan 2013, 11:37 AM
Hi,

My scenario is , If user did not check atleast sinlge Item from the List box then i have to show an error message like please select Items/Items from the RadListBox. For this i went to Custom validator, and writen a Client side function . Actually this Validator function has to execute if user clicked on the button or while post back... but this Custom validator function is going to excute while user click on the Check box Item. Please provide ur advice to over come from this scenario. I am adding my code snipet.

If i check or uncheck the RadListbox item then this JavaScript function is excuting ...
Is_Event_selected(sender, args) {} .....

please provide ur Comments ASAP

<%

 

@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>

<!

 

 

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<

 

 

html xmlns="http://www.w3.org/1999/xhtml">

<

 

 

head runat="server">

 

<title></title>

 

<telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" />

 

<script type="text/javascript">

 

function Is_Event_selected(sender, args) {

 

debugger;

 

var lstbox = $find("lstEvents");

 

var chkedItems_Count = lstbox.get_checkedItems().length;

args.IsValid = chkedItems_Count > 0;

}

 

</script>

</

 

 

head>

<

 

 

body>

 

<form id="form1" runat="server">

 

<telerik:RadScriptManager ID="RadScriptManager1" runat="server">

 

<Scripts>

<%

 

--Needed for JavaScript IntelliSense in VS2010--%>

<%

 

--For VS2008 replace RadScriptManager with ScriptManager--%>

 

<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />

 

<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />

 

<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />

 

</Scripts>

 

</telerik:RadScriptManager>

 

<script type="text/javascript">

 

//Put your JavaScript code here.

 

</script>

 

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">

 

</telerik:RadAjaxManager>

 

<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>

 

</form>

</

 

 

body>

</

 

 

html>

1 Answer, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 07 Feb 2013, 11:14 AM
Hi Prasaad,

If you attempt to validate the RadListBox when the user clicks on a button or when a PostBack occurs, I can suggest you to remove the ControlToValidate property from the CustomValidator. Thus, the function, which checks the count of the checked items, would be executed only when a PostBack is fired.

Regards,
Nencho
the Telerik team
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 their blog feed now.
Tags
ListBox
Asked by
Prasad
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Share this question
or