G
Guest
Could someone please help me with some validation. I have to write code which
checks to see whether a dropdown list is populated with a value or a checkbox
is checked. I want the code to run on the on-click of a button.
My page has 1 dropdown list and two checkboxes. So I either want the user
to choose an item from the dropdownlist OR tick a checkbox(it doesn't matter
if they tick both checkboxes). I can't allow the user to fill in the
dropdownlist and tick a checkbox.
Im pretty new to coding and im not sure what is the best way to do this. Can
I use a custom validator or would I be better putting it on the on-click
event of the button on the code behind page. I would also like the error
messages to appear in my Error Summary which is in a panel at the bottom of
my page.
This is the event ill probably need to place my code
private void Button1_Click(object sender, System.EventArgs e)
{
//Validate whether a item is selected in dropdown list OR a one/both
checkboxes is checked. Cant allow user to check a checkbox and choose an item
from the dropdown list
}
Could someone please help me write this code, im really not sure at all.
Here is the html code. for the page im using.
<table style="WIDTH: 305px; HEIGHT: 102px" height="102" width="305"
border="2">
<tr>
<td style="HEIGHT: 31px"><asp:dropdownlist id="DropDownList1" runat="server"
Width="231px">
<asp:ListItem></asp:ListItem>
<asp:ListItem Value="Green">Green</asp:ListItem>
<asp:ListItem Value="Blue">Blue</asp:ListItem>
<asp:ListItem Value="Yellow">Yellow</asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:dropdownlist></td>
</tr>
<tr>
<td style="HEIGHT: 31px"><asp:checkbox id="CheckBox2" runat="server"
Text="No Colour"></asp:checkbox>
<asp:checkbox id="CheckBox1" runat="server" Text="Any Colour"></asp:checkbox>
</td>
</tr>
<TR>
<TD><asp:button id="Button1" runat="server" Text="Button"></asp:button></TD>
</TR>
<tr><td>
<asp
anel id="pnMessagePanel" runat="server" Height="45px" Width="98.13%">
<asp:ValidationSummary id="vsSummaryOfErrors" runat="server" Width="897px"
Height="8px" BackColor="#ffffcc">
</asp:ValidationSummary>
</asp
anel>
</td></tr>
</table>
Thanks very much for any help anyone can give me
checks to see whether a dropdown list is populated with a value or a checkbox
is checked. I want the code to run on the on-click of a button.
My page has 1 dropdown list and two checkboxes. So I either want the user
to choose an item from the dropdownlist OR tick a checkbox(it doesn't matter
if they tick both checkboxes). I can't allow the user to fill in the
dropdownlist and tick a checkbox.
Im pretty new to coding and im not sure what is the best way to do this. Can
I use a custom validator or would I be better putting it on the on-click
event of the button on the code behind page. I would also like the error
messages to appear in my Error Summary which is in a panel at the bottom of
my page.
This is the event ill probably need to place my code
private void Button1_Click(object sender, System.EventArgs e)
{
//Validate whether a item is selected in dropdown list OR a one/both
checkboxes is checked. Cant allow user to check a checkbox and choose an item
from the dropdown list
}
Could someone please help me write this code, im really not sure at all.
Here is the html code. for the page im using.
<table style="WIDTH: 305px; HEIGHT: 102px" height="102" width="305"
border="2">
<tr>
<td style="HEIGHT: 31px"><asp:dropdownlist id="DropDownList1" runat="server"
Width="231px">
<asp:ListItem></asp:ListItem>
<asp:ListItem Value="Green">Green</asp:ListItem>
<asp:ListItem Value="Blue">Blue</asp:ListItem>
<asp:ListItem Value="Yellow">Yellow</asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:dropdownlist></td>
</tr>
<tr>
<td style="HEIGHT: 31px"><asp:checkbox id="CheckBox2" runat="server"
Text="No Colour"></asp:checkbox>
<asp:checkbox id="CheckBox1" runat="server" Text="Any Colour"></asp:checkbox>
</td>
</tr>
<TR>
<TD><asp:button id="Button1" runat="server" Text="Button"></asp:button></TD>
</TR>
<tr><td>
<asp

<asp:ValidationSummary id="vsSummaryOfErrors" runat="server" Width="897px"
Height="8px" BackColor="#ffffcc">
</asp:ValidationSummary>
</asp

</td></tr>
</table>
Thanks very much for any help anyone can give me