RickEpnet
asked on
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.
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"> </td>
<td> </td>
<td width="30"> </td>
<td> </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> </td>
<td> </td>
</tr>
<tr>
<td colspan="2">quanity * </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </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> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<asp:Button runat="server" Text="Submit" id="reg" OnClick="ValidateBtn_Click" />
</form>
<p> </p>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Check this as well: http://aspnet.4guysfromrolla.com/articles/092006-1.aspx
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>
ASKER
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.
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
ASKER
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.
Thanks everyone.