A method of Asp:checkbox verifying non-null

Source: Internet
Author: User

Sometimes the form must be non-empty, the checkbox is troublesome, can not be used RequiredFieldValidator control, so I use JS and CustomValidator control combination to achieve.

JS Code:

 <script language= "javascript" type= "Text/javascript" >//Verify that the checkbox is not empty function checkisnotnull (source, args) {var ch1 = document.getElementById (' <%= type1.            ClientID%> '); var CH2 = document.getElementById (' <%= type2.            ClientID%> '); var CH3 = document.getElementById (' <%= type3.            ClientID%> '); var CH4 = document.getElementById (' <%= type4.            ClientID%> '); var ch5 = document.getElementById (' <%= type5.            ClientID%> '); var ch6 = document.getElementById (' <%= type6.        ClientID%> '); if (ch1.checked) {args.            IsValid = true;        Return } if (ch2.checked) {args.            IsValid = true;        Return } if (ch3.checked) {args.            IsValid = true;        Return } if (ch4.checked) {args.            IsValid = true;        Return } if (ch5.checked) {args.       IsValid = true;     Return } if (ch6.checked) {args.            IsValid = true;        Return } args. IsValid = false;}

ASPX code:

&LT;TD colspan="2"> <asp:checkbox runat="Server"ID ="type1"Font-size="Large"Text ="Game Video Book"/> &nbsp;&nbsp;&nbsp; <asp:checkbox runat="Server"ID ="type2"Font-size="Large"Text ="Home Entertainment Book"/> &nbsp;&nbsp;&nbsp; <asp:checkbox runat="Server"ID ="Type3"Font-size="Large"Text ="HD AV book"/> &nbsp;&nbsp;&nbsp; <asp:checkbox runat="Server"ID ="Type4"Font-size="Large"Text ="Business Office Book"/> &nbsp;&nbsp;&nbsp; <asp:checkbox runat="Server"ID ="Type5"Font-size="Large"Text ="the All-round student"/> &nbsp;&nbsp;&nbsp; <asp:checkbox runat="Server"ID ="Type6"Font-size="Large"Text ="Lightweight and Portable book"/> <asp:customvalidator id="CustomValidator1"runat="Server"Forecolor="Red"Errormessage="can't be empty! "clientvalidationfunction="Checkisnotnull"></asp:customvalidator> </td>

Show Results:

A method of Asp:checkbox verifying non-null

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.