Here is the simple code:
<script>Here I have created "CustomValidator" which is pointing to "ValidateChkBxLst" Javascript function to validate it clientside without postback. Isn't it simple?
function ValidateChkBxLst(source, args) {
var chkListModules = document.getElementById('<%= chkBxLst.ClientID%>'); var chkListinputs = chkListModules.getElementsByTagName("input"); for (var i = 0; i < chkListinputs.length; i++) { if (chkListinputs[i].checked) { args.IsValid = true; return; } } args.IsValid = false; } </script> <asp:checkboxlist id="chkBxLst" repeatcolumns="3" repeatdirection="Vertical" runat="server"/> <asp:customvalidator clientvalidationfunction="ValidateChkBxLst" errormessage="CheckBox List" id="cvList" runat="server" text="Please select at least one checkbox." />
Thanks
Thanks for the helpful Post. You explained it very well
ReplyDelete