ASP.NET Check Box Validation

I don't generally develop in ASP.NET but I am this time so be easy on me.

I am using VB and I am not developing Visual Studio.

The customer has check boxes 3 groups of them. They want at least one box checked in each group is there a way to do this?

See code for the check box grouping this might help explain.


<%@ Page Language="vb" AutoEventWireup="false" Inherits="homeh.WebForm1" CodeFile="test.aspx.vb" enableEventValidation="false" validateRequest=false%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form runat="server">
<asp:ValidationSummary DisplayMode="BulletList" HeaderText="Please correct these Errors" ID="pagesum" runat="server" ShowMessageBox="true" ShowSummary="false" /> 
<table width="933" border="0" cellspacing="0" cellpadding="3">
<tr>
                      <td colspan="2" bgcolor="#CCCCCC">solution <span class="style10">*</span></td>
                      <td width="30">&nbsp;</td>
      <td>&nbsp;</td>
      <td width="30">&nbsp;</td>
      <td>&nbsp;</td>
      <td colspan="2" bgcolor="#CCCCCC">time frame for installation <span class="style10">*</span></td>
    </tr>
                    <tr>
                      <td width="30" bgcolor="#CCCCCC"><asp:CheckBox Checked="false" ID="billpay" runat="server" /></td>
                      <td bgcolor="#CCCCCC">bill pay</td>
                      <td><asp:CheckBox Checked="false" ID="internet" runat="server" /></td>
                      <td>internet</td>
                      <td><asp:CheckBox Checked="false" ID="retail" runat="server" /></td>
                      <td>retail</td>
                      <td width="30" bgcolor="#CCCCCC"><asp:CheckBox Checked="false" ID="asap" runat="server" /></td>
                      <td bgcolor="#CCCCCC">asap</td>
    </tr>
                    <tr>
                      <td bgcolor="#CCCCCC"><asp:CheckBox Checked="false" ID="financial" runat="server" /></td>
                      <td bgcolor="#CCCCCC">financial</td>
                      <td><asp:CheckBox Checked="false" ID="music" runat="server" /></td>
                      <td>music</td>
                      <td><asp:CheckBox Checked="false" ID="ticketing" runat="server" /></td>
                      <td>ticketing</td>
                      <td bgcolor="#CCCCCC"><asp:CheckBox Checked="false" ID="oneto3months" runat="server" /></td>
                      <td bgcolor="#CCCCCC">1 to 3 months</td>
                    </tr>
                    <tr>
                      <td bgcolor="#CCCCCC"><asp:CheckBox Checked="false" ID="hr" runat="server" /></td>
                      <td bgcolor="#CCCCCC">human resources</td>
                      <td><asp:CheckBox Checked="false" ID="ordere" runat="server" /></td>
                      <td>order entry</td>
                      <td><asp:CheckBox Checked="false" ID="wayfinding" runat="server" /></td>
                      <td>wayfinding</td>
                      <td bgcolor="#CCCCCC"><asp:CheckBox Checked="false" ID="m3months" runat="server" /></td>
                      <td bgcolor="#CCCCCC">more than 3 months</td>
                    </tr>
                    <tr>
                      <td bgcolor="#CCCCCC"><asp:CheckBox Checked="false" ID="informational" runat="server" /></td>
                      <td bgcolor="#CCCCCC">informational</td>
                      <td><asp:CheckBox Checked="false" ID="photo" runat="server" /></td>
                      <td>photo</td>
                      <td><asp:CheckBox Checked="false" ID="other" runat="server" /></td>
                      <td>other</td>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                    </tr>
                    <tr>
                      <td colspan="2">quanity *                     </td>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                    </tr>
                    <tr>
                      <td><asp:TextBox ID="quanity" runat="server" Width="40" />
                      <asp:RequiredFieldValidator
            ControlToValidate="quanity"
            Display="None" EnableClientScript="true"
            ErrorMessage="quanity is required " id="REQquanity" runat="server"
            Width="100%"> </asp:RequiredFieldValidator></td>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                    </tr>
  </table>
  
  <asp:Button runat="server" Text="Submit" id="reg" OnClick="ValidateBtn_Click"  />
</form>
<p>&nbsp;</p>
</body>
</html>

Open in new window

LVL 14
RickEpnetAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cdaly33Commented:
Search for Checkbox on this page.  It has some good explanations and examples.

http://msdn.microsoft.com/en-us/library/aa479013.aspx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
guru_samiCommented:
0
masterpassCommented:
This may not be a solution, but in the cases you described above the easiest thing you can do instead of the JS is changing the checkbox to radiobutton and assigning a groupname to them and set checked=true for one of the radiobutton.
<tr>
  <td width="30" bgcolor="#CCCCCC"><asp:RadioButton Checked="true" ID="billpay" runat="server" GroupName="grp1"/></td>
  <td bgcolor="#CCCCCC">bill pay</td>
  <td><asp:RadioButton Checked="false" ID="internet" runat="server" GroupName="grp1"/></td>
  <td>internet</td>
  <td><asp:RadioButton Checked="false" ID="retail" runat="server" GroupName="grp1"/></td>
  <td>retail</td>
  <td width="30" bgcolor="#CCCCCC"><asp:RadioButton Checked="false" ID="asap" runat="server" GroupName="grp1"/></td>
  <td bgcolor="#CCCCCC">asap</td>
</tr>

Open in new window

0
RickEpnetAuthor Commented:
I think I figured out what I am going to do.

When I submit the form I am going to run a variation of this.

I will test it in the morning.
	Private Sub checkboxis()
     Dim strchklist As String = ""
     Dim li As ListItem
     For Each li In solution.Items
          If li.Selected Then
               strchklist += li.Text + " "
          End If
     Next
     If strchklist = "" Then
                      sbScript.Append("<script language=JavaScript>" + ControlChars.Lf)
		      sbScript.Append("<!--" + ControlChars.Lf)
		      sbScript.Append("alert('Please Select a Check Box'); " + ControlChars.Lf)
		      sbScript.Append("// -->" + ControlChars.Lf)
		      sbScript.Append("</script>" + ControlChars.Lf)
      
	    	  RegisterStartupScript(scriptKey, sbScript.ToString())
     Else
         sendtheemail
     End If
	End Sub

Open in new window

0
RickEpnetAuthor Commented:
Although this was the right way to do it it was too much work for the money on this job. I choose a less desirable but easier way of validating the data. The post did have samples of VB the other was C#. I did ask for help with VB.

      Thanks everyone.  
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.