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>