PDA

View Full Version : custom compare validation


reubenb
07-02-2009, 11:16 AM
hey

i want a validation to check that, if the user selects "Yes" in a checkbox - that they provide details. and if not, then they can just select "No"
How do I do that?

This is what I have at the moment:

<table border="0">
<tr>
<td class="tbl3col1">Problem?</td>
<td class="tbl3col2"><asp:radiobuttonlist id="Problem" runat="server">
<asp:listitem id="Yes" runat="server" value="Yes" />
<asp:listitem id="No" runat="server" value="No" />
</asp:radiobuttonlist><asp:RequiredFieldValidator ID="validate_problem" runat="server" ControlToValidate="Problem"
ErrorMessage="* You must tell us if you have a problem" Display="dynamic">* </asp:RequiredFieldValidator></td>
<td class="tbl3col3"><textarea id="Problem_d" class="textfield" runat="server" /></td>
</tr>
</table>


so basically at the moment it will make them say yes or no. but i want it to make them write something in Problem_d if they said yes to the question (ie Problem=yes)

how can i do this??

Thanks

Mike_O
07-02-2009, 06:20 PM
Hey reubenb,

I think the solution to your problem can be summarized in this article:
http://www.beansoftware.com/ASP.NET-FAQ/Client-Conditional-RequiredFieldValidator.aspx

The basic idea here is that you have to use a CustomValidator, instead of the RequiredFieldValidator.

Mike