Saturday, 10 August 2013

How to create jQuery function to validate custom validator on ASP checkbox list

How to create jQuery function to validate custom validator on ASP checkbox
list

Here is my code for checkbox list: Data is bounded with Look Up Table
asp:CheckBoxList ID="cbl_AppliancePresent" ClientIDMode="Static"
CssClass="cbl_AppliancePresent" runat="server" DataTextField="Appliance"
DataValueField="ApplianceID" RepeatDirection="Horizontal">
Here is the Custom Validator:
<asp:CustomValidator ID="SpecifyAppliances" ClientIDMode="Static"
runat="server" EnableClientScript="true" ErrorMessage="Please select
Vacant-not secure reasons" Font-Bold="True"
ClientValidationFunction="ValidateNotSecure" ForeColor="Red"
Font-Size="Small"></asp:CustomValidator>
Function:
function ValidateNotSecure(source, args) {
var options = $('.cbl_AppliancePresent');
for (var i = 0; i < options.length; i++) {
if (options[i].checked) {
EnableValidator('SpecifyAppliances');
args.IsValid = true;
return false;
}
}
DisableValidator('SpecifyAppliances');
args.IsValid = false; }

No comments:

Post a Comment