Hello Friends, As we all know we can not use checkboxlist control with required field validator control, we need to have a solution for that. I created a javascript function which will do the job of required field validator control. The JS function returns 'true' or 'false'. If checkboxlist control has got atleast one checkbox selected, the function will return 'true' else it will return 'false'
I have CheckBoxList1 control on my web page. To validate that control here is the script. You will have to change control name in the script while implementing this script.
function ValidateCheckboxList() { var chkitems = document.getElementById('<%= CheckBoxList1.ClientID %>'); var chkitm = chkitems.getElementsByTagName("input"); for (var i = 0; i < chkitm.length; i++) { if (chkitm[i].checked) { return true; } } return false; }
To Implement, simple call this function wherever you need. I called this function on a button click event.
" a b c onclick="return ValidateCheckboxList();" />"
I have attached an aspx file, to see it running, just copy past file in any website project and run the page.
~Sanjivani
AttachmentsUsing function... (26723-122010-Default.aspx.txt)Using function... (26723-122013-Default.aspx.txt)
|
No responses found. Be the first to respond and make money from revenue sharing program.
|