这是我的checkbox
列表代码: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">
</asp:CheckBoxList>
这是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 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; }