• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 412
  • Last Modified:

checkbox checked validator

On single form I have 25 different checkboxes.I need some validator that will check if there is any of these checkboxes checked before submit button click (at least one checkbox should be checked before submit).What kind of validator should I use and how to validate all 25 checkboxes?

Thanks.
0
kahvedzic
Asked:
kahvedzic
  • 4
  • 2
1 Solution
 
Imran Javed ZiaCommented:
0
 
kahvedzicAuthor Commented:
Second link is for check box list, first link is a bit complicated but will try it.
0
 
kahvedzicAuthor Commented:
This custom control is doing validation in different way. I need to validate that at least one check box from 25 on form is selected.I dont want to know which one it is or how many of them were selected.I just want to check if one of them is selected so that form can be submited.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
kahvedzicAuthor Commented:
I use javascript to validate check boxes and did it this way:

html:

    <asp:CheckBox ID="CheckBox1" runat="server" Text="1" />
    <asp:CheckBox ID="CheckBox2" runat="server" Text="2" />
    <asp:CheckBox ID="CheckBox3" runat="server" Text="3" />
    <asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="CheckBoxCheck" ErrorMessage="Check at least one application" ValidationGroup="VG1"></asp:CustomValidator>
    <asp:Button ID="btn1" runat="server" Text="Submit" ValidationGroup="VG1" />

java script:

        function CheckBoxCheck(sender, args) {
            if (document.getElementById("CheckBox1").checked || document.getElementById("CheckBox2").checked || document.getElementById("CheckBox3").checked) {
                args.IsValid = true;
                return;
            }
            args.IsValid = false;
        }
0
 
Imran Javed ZiaCommented:
you can also use loop in CheckBoxCheck javascript and verify if any checkbox is checked
0
 
kahvedzicAuthor Commented:
this solution is much simplier than the one provided in first post, but thanks for help.
0

Featured Post

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now