RequiredFieldValidator

J

jonknutsonhome

Does anyone know exactly how a RequiredFieldValidator works?

Here is my situation.

I am now in charge of a new project.

I am making a new contactus.aspx page with required fields.
Easy to do, not an issue.

The left navigaion has a user control (Newsletter Signup Control) that
allows you to sign up for newsletters and contains an email Textbox and
submit button.

This user control has RequiredFieldValidator on it as well.

When I submit information on the main section of the contactus.aspx
form and click submit, it forces me to fill in the required fields in
the user control as well.

Does anyone know how to have 2 different areas of required fileds on
the same page like this?

So I want to be able submit the contactus.aspx page without also having
to enter information into the user control and vise-versa.

Thanks
 
A

Adrian Parker

If you're using net 2.0 then you can group your validators and only do the ones you want.

If you're using v1.1 then what I've done is to disable all validators when they're created, and enabled the specific ones you want
to verify on each button click event handler.

The following routine switches all validators on for a page, but you could modify it just to enable the validators you want..

Public Sub ToggleValidators(ByVal bToggle As Boolean)
Dim bv As BaseValidator
For Each bv In Page.Validators
bv.Enabled = bToggle
Next
End Sub

I also, enable the validator for the specific control in any onchange event, easily done if you set your validator ID to the same ID
as your control but with "_validator" added to the end. In the onchange events, you can then do something like..

Dim CV As CustomValidator
Dim doChange As Boolean = True
Dim ID As String = CType(source, CustomValidator).ControlToValidate

CV = FindControl(ID + "_validator")
If Not CV Is Nothing Then
CV.Enabled = True
CV.Validate()
doChange = CV.IsValid
End If
If doChange Then
' do onchange processing
End If

HTH
 

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

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top