473,396 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Validation of OR of multiple controls

Hi All,

I'm having problems setting up a validation mechanism that covers three
optional <asp:textbox> - Only one of these need to be filled - any one.

The standard RequiredFieldValidator will insist on each one being filled. I
thought I could use the Page_Load handler but if the second postback makes
one validator happy, then other two persist in being not valid so the
..Enabled=False does not seem to be doing what I expect.

Any tips on how to do this?

Thanks
Ananda
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

If IsPostBack Then

If (Me.txtHome.Text = "" And Me.txtWork.Text = "" And Me.txtMobile.Text =
"") Then

Me.HomePhoneValidator.Enabled = True

Me.WorkPhoneValidator.Enabled = True

Me.MobilePhoneValidator.Enabled = True

Me.Validate()

Else

Me.HomePhoneValidator.Enabled = False

Me.WorkPhoneValidator.Enabled = False

Me.MobilePhoneValidator.Enabled = False

Me.Validate()

End If

End If

End Sub
Nov 17 '05 #1
2 4147
Getting nearer...

I found different behaviours with Netscape 4.7x vs IE 6.0.

IE 6.0 did not show whole page postback behaviour whilst Netscape 4.7x did -
so I have for the time being, set the whole page to ClientTarget="downlevel"
and both act the same.

Is there any other way?

Ananda

"Ananda Sim" <an*******@optushome.com.au.invalid> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi All,

I'm having problems setting up a validation mechanism that covers three
optional <asp:textbox> - Only one of these need to be filled - any one.

The standard RequiredFieldValidator will insist on each one being filled. I thought I could use the Page_Load handler but if the second postback makes
one validator happy, then other two persist in being not valid so the
.Enabled=False does not seem to be doing what I expect.

Any tips on how to do this?

Thanks
Ananda
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

If IsPostBack Then

If (Me.txtHome.Text = "" And Me.txtWork.Text = "" And Me.txtMobile.Text =
"") Then

Me.HomePhoneValidator.Enabled = True

Me.WorkPhoneValidator.Enabled = True

Me.MobilePhoneValidator.Enabled = True

Me.Validate()

Else

Me.HomePhoneValidator.Enabled = False

Me.WorkPhoneValidator.Enabled = False

Me.MobilePhoneValidator.Enabled = False

Me.Validate()

End If

End If

End Sub

Nov 17 '05 #2
Thanks Hans,

A clarification query -

"Hans Kesting" <ne***********@spamgourmet.com> wrote in message
news:uZ*************@tk2msftngp13.phx.gbl...
The difference in behavior is because for netscape no client-side code is
generated,
so everything is done serverside.

One way to solve this is to use a CustomValidator which will always be
processed server-side.
This validator is specifically for cases where the regular validators can't be used.
In the server-side validate event you can check if at least (or only) one of your three
fields is filled.


1. If I use CustomValidator - without using ClientTarget="downlevel", the
event does not seem to trigger at all. i.e. if the textboxes are blank and I
use

Sub CustomValidator.......
if txtFirstname.text = "" AND txtSurname.text="" then........
args.isvalid=false
End Sub

that does not trigger at all. Correct?

Note: CustomValidator (or any validator) will only bind to *ONE*
ControlToValidate. And I have tried CustomValidator for connection to
database to see whether the entered value is in a table. That works fine.
But this approach for this example does not?
2. If I use three RequiredFieldValidators that is ok as well because that
means ALL must textboxes must be filled. Correct?

3. So I
a. create three RequiredFieldValidators
b. programmatically set them to enabled=false or true depending on my
conditions
c. set ClientTarget="downlevel"
so that all validation is serverside. So I lose all clientside validation
that is auto generated for all other controls.
Correct?
Many thanks in advance

Ananda
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Richard Payne | last post by:
I am developing a web application that utilises multiple grids, panels, validation controls etc on the same page. I have added the appropriate code to pop up dialogs to confirm delete in...
0
by: George Jordanov Ivanov | last post by:
Hi there, I have a problem related with validation of a container control, containing other container controls. Scenario: I have a dialog based Windows form, containing a group control (which...
4
by: earwicker | last post by:
I recently deployed a web application which contains a user registration form with the usual fields: name, address, email, password, etc. Each of the TextBoxes uses a validation control to verify...
2
by: Avad | last post by:
I have a following screen. The login is a "user control" with validations controls in it. This side I have address book in which "name" is required field. But when I click on "add new user" the...
7
by: A.M | last post by:
Hi, I have a validation control in my page that upon any invalid data, it disables all buttons in the page. basicly i don't have any postback in the page if the validator finds any error. How...
1
by: dhurwitz | last post by:
Hi I have developed a web app with a dozen or so pages, which allows searching for and editing orders by OrderID. There is a search page for entering multiple search criteria. In addition, each...
5
by: M | last post by:
Hi, it's possible to append a custom action to a client-side verification of a validation control ? I have a validator summary control that shows (automatically) a message box if the validation...
3
by: Jonas | last post by:
Hi! I have aspx-page where I use multiple panels to make room for more controls than would otherwise fit onto one page. On submit, the controls on all panels, visible or not, should be validated...
12
by: Dabbler | last post by:
I need to insure that at least one of three phone number fields has a value (requiredfield) but I'm not sure of a way to implement this without server side logic. Is there a way to use the...
10
by: gweasel | last post by:
What is the best way to apply a Validation Rule - or rather, where is the best place to put it? Is there an advantage to putting it on the field in the table vs setting the validation rule on the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.