Re field validation

N

News

Hi,
I am new to asp.net 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>
</asp:radiobuttonlist>
<asp:requiredfieldvalidator
id="RequiredFieldValidator_is_override"
runat="server"
ErrorMessage="You must choose a valid Override option."
ControlToValidate="is_override">
</asp:requiredfieldvalidator>

<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!

Thanks
 
V

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!")
Else
' do whatever (redirect, etc...)
End If
End Sub
 
P

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" (http://www.peterblum.com/vam/home.aspx). 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
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 

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

Top