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(o bject sender, System.EventArg s 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:drop downlist id="DropDownLis t1" runat="server"
Width="231px">
<asp:ListItem ></asp:ListItem>
<asp:ListItem Value="Green">G reen</asp:ListItem>
<asp:ListItem Value="Blue">Bl ue</asp:ListItem>
<asp:ListItem Value="Yellow"> Yellow</asp:ListItem>
<asp:ListItem ></asp:ListItem>
</asp:dropdownlis t></td>
</tr>
<tr>
<td style="HEIGHT: 31px"><asp:chec kbox 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:butt on id="Button1" runat="server" Text="Button"></asp:button></TD>
</TR>
<tr><td>
<asp:panel id="pnMessagePa nel" runat="server" Height="45px" Width="98.13%">
<asp:Validation Summary id="vsSummaryOf Errors" runat="server" Width="897px"
Height="8px" BackColor="#fff fcc">
</asp:ValidationS ummary>
</asp:panel>
</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(o bject sender, System.EventArg s 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:drop downlist id="DropDownLis t1" runat="server"
Width="231px">
<asp:ListItem ></asp:ListItem>
<asp:ListItem Value="Green">G reen</asp:ListItem>
<asp:ListItem Value="Blue">Bl ue</asp:ListItem>
<asp:ListItem Value="Yellow"> Yellow</asp:ListItem>
<asp:ListItem ></asp:ListItem>
</asp:dropdownlis t></td>
</tr>
<tr>
<td style="HEIGHT: 31px"><asp:chec kbox 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:butt on id="Button1" runat="server" Text="Button"></asp:button></TD>
</TR>
<tr><td>
<asp:panel id="pnMessagePa nel" runat="server" Height="45px" Width="98.13%">
<asp:Validation Summary id="vsSummaryOf Errors" runat="server" Width="897px"
Height="8px" BackColor="#fff fcc">
</asp:ValidationS ummary>
</asp:panel>
</td></tr>
</table>
Thanks very much for any help anyone can give me
Comment