I've looked at a dozen previous answers on here nothing has worked for me. I need a form where a checkbox must be checked in order to submit. I am using C# and am pretty new to it, I just found out the RequiredFieldValidator that works with text box's won't work with checkboxes so I need another way to do this.
On submit the data in the fields gets sent to a MS SQL database. I have more fields then the one's shown below but I thought I would condense it for this post and removed everything but one text box and the checkbox I need validated upon submit.
I'd like it to do this on submit:
<form id="form1" runat="server">
<asp:Label ID="NameLbl" runat="server" Text="Label"></asp:Label><asp:RequiredFieldValidator
ID="NameRFV" runat="server" ErrorMessage="NameTxtBox"></asp:RequiredFieldValidator>
<asp:TextBox ID="NameTxtBox" runat="server"></asp:TextBox>
<br />
<asp:Label ID="AliveLbl" runat="server" Text="Are you alive?"></asp:Label>
<asp:CheckBox ID="AliveChkBox" runat="server" />
<asp:Button ID="Submit" class="btn btn-primary" runat="server" Text="Submit" OnClick="Submit_Click" />
</form>
I've read about using CustomValidator but I can't get anything to function properly with it. People keep saying you need to compile/build your code for it to work and I simply don't no how to do that.
Will consider javascript options as well. I can also use a CheckboxList instead if you know of a better way to validate those.