Re field validation



I am new to and unfortunately, have to learn as I go.
Here is a "problem".

I have got two radio buttons No and Yes and text box that has to be fiiled
in only if Yes is clicked. How can I validate this?

Here is a code:

<asp:radiobuttonlist RepeatDirection=Horizontal RepeatLayout=Table
id="is_override" runat="server">
<asp:listitem text="No" Value="0"></asp:listitem>
<asp:listitem text="Yes" Value="1"></asp:listitem>
ErrorMessage="You must choose a valid Override option."

<asp:textbox size=50 MaxLength="100" id="reason" runat="server" Text="" />
<!--- here I need some type of validation if a user cliked Yes --->

Help is very much appreciated!


VB Programmer

Can you do something like this:

1. Add a button.
2. Add this code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If is_override.SelectedValue = 1 And reason.Text = "" Then
Response.Write("You must enter a reason!")
' do whatever (redirect, etc...)
End If
End Sub

Peter Blum

None of the Microsoft validators have the ability to turn themselves on
based on another element of the page. There are two solutions.

1. Write a custom validator. If you want it to work on the client side, you
will have to figure out that code too.

2. I have written a replacement for Microsoft's validation, "Professional
Validation And More" ( Each of its
validators has a new property, "Enabler", where you can define a rule that
smartly enables the validator. On my RequiredTextValidator, you can set the
Enabler to look at the radiobutton before enabling itself. This works fully
on the client-side. In fact, Professional Validation And More's 22
validators support many more browsers on the client-side than Microsoft: IE,
IE/Mac, Netscape/Mozilla, Opera 7 and Safari.

--- Peter Blum
Email: (e-mail address removed)
Creator of "Professional Validation And More" at

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question