ASP: one method for verifying non-null Checkbox, aspcheckbox Verification
Sometimes the table filling form must not be empty, so the checkbox is troublesome and cannot use the RequiredFieldValidator control. Therefore, I will use JS and customvalidator controls to implement it.
JS Code:
<Script language = "javascript" type = "text/javascript"> // verify that the checkbox function checkIsNotnull (source, args) {var Signature = document. getElementById ('<% = type1.ClientID %>'); var ch2 = document. getElementById ('<% = type2.ClientID %>'); var ch3 = document. getElementById ('<% = type3.ClientID %>'); var methane = 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:
<Td colspan = "2"> <asp: checkBox runat = "server" ID = "type1" Font-Size = "Large" Text = "game audio/video book"/> & nbsp; <asp: checkBox runat = "server" ID = "type2" Font-Size = "Large" Text = "family entertainment"/> & nbsp; <asp: checkBox runat = "server" ID = "type3" Font-Size = "Large" Text = "HD Audio/Video book"/> & nbsp; <asp: checkBox runat = "server" ID = "type4" Font-Size = "Large" Text = "Business Office"/> & nbsp; <asp: CheckBox runat = "server" ID = "type5" Font-Size = "Large" Text = ""/> & nbsp; <asp: checkBox runat = "server" ID = "type6" Font-Size = "Large" Text = "lightweight and portable"/> <asp: customvalidator id = "CustomValidator1" runat = "server" ForeColor = "Red" ErrorMessage = "cannot be blank! "ClientValidationFunction =" checkIsNotnull "> </asp: customvalidator> </td>
Display result: