473,397 Members | 1,950 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,397 software developers and data experts.

How to validate a control that might be empty

Hello,

I have a form in which the customer can enter their personal details.
Some customers will have an account number, in which case they are
allowed to enter this and not have to enter their address.

How do I do validation for this? They must enter one of account number
or address, but need not supply both.

AFAICS, validation controls only fire if the control to be validated
contains something, so if they don't enter an account number and don't
enter an address, validation won't happen.

Any ideas? TIA

--
Alan Silver
(anything added below this line is nothing to do with me)
Jun 19 '06 #1
4 904
You willhave to use custom validation.
Here is an example for dropdownlist.. but you can use the same concept for
any control or combination of controls on your page.

http://www.netomatix.com/Development...Validator.aspx
"Alan Silver" <al*********@nospam.thanx.invalid> wrote in message
news:GA**************@nospamthankyou.spam...
Hello,

I have a form in which the customer can enter their personal details. Some
customers will have an account number, in which case they are allowed to
enter this and not have to enter their address.

How do I do validation for this? They must enter one of account number or
address, but need not supply both.

AFAICS, validation controls only fire if the control to be validated
contains something, so if they don't enter an account number and don't
enter an address, validation won't happen.

Any ideas? TIA

--
Alan Silver
(anything added below this line is nothing to do with me)

Jun 19 '06 #2
It sounds like a job for the CustomValidator control.

This will get you started:

http://msdn2.microsoft.com/en-us/lib...nfunction.aspx

--
-Demetri
"Alan Silver" wrote:
Hello,

I have a form in which the customer can enter their personal details.
Some customers will have an account number, in which case they are
allowed to enter this and not have to enter their address.

How do I do validation for this? They must enter one of account number
or address, but need not supply both.

AFAICS, validation controls only fire if the control to be validated
contains something, so if they don't enter an account number and don't
enter an address, validation won't happen.

Any ideas? TIA

--
Alan Silver
(anything added below this line is nothing to do with me)

Jun 19 '06 #3
In article <GA**************@nospamthankyou.spam>, Alan Silver
<al*********@nospam.thanx.invalid> writes
<snip>
How do I do validation for this? They must enter one of account number
or address, but need not supply both.

AFAICS, validation controls only fire if the control to be validated
contains something, so if they don't enter an account number and don't
enter an address, validation won't happen.


OK, I just found this which might be of use to others (watch out for URL
wrapping)...

http://groups.google.co.uk/group/mic...amework.aspnet
/browse_frm/thread/cd27e867f2b65cfb/9c58c0ab63b1c7ee

Basically it seems that if you leave the ControlToValidate property
empty, then the validator always fires, even if the control is empty.

HTH

--
Alan Silver
(anything added below this line is nothing to do with me)
Jun 19 '06 #4
In article <56**********************************@microsoft.co m>, Demetri
<De*****@discussions.microsoft.com> writes
It sounds like a job for the CustomValidator control.


Demetri and Winista,

A custom validator only fires if there is something in the control, that
was the point of my post. I know how to use the custom validator, but
was stuck with the problem that the user is required to enter one of two
pieces of information. If they don't enter either, the validator doesn't
fire. It doesn't matter what validator you use, it just doesn't fire.

I got around it partially by not setting the ControlToValidate property,
making the validator fire whenever a submit button is clicked. That
limited me to having to pull all the data to be validated inside the
function, meaning that I couldn't have a generic function that would do
the validation for several controls. This was a pain, but not the end of
the world.

I'd still like to know if there is a more elegant solution. Thanks
anyway.

--
Alan Silver
(anything added below this line is nothing to do with me)
Jun 19 '06 #5

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

Similar topics

1
by: L Mehl | last post by:
On my cmdSaveRecord, I check a couple of fields to confirm that an entry has been made before allowing the Save. I decided to - not put validation rules in table structure, and - validate on...
1
by: Jon Davis | last post by:
This is always returning True, even when fields are empty. Why? private bool ValidatePageOne() { bool ret = true; foreach (Control ctrl in PageOnePanel.Controls) { if...
3
by: Jon Davis | last post by:
This is always returning True, even when fields are empty. Why? private bool ValidatePageOne() { bool ret = true; foreach (Control ctrl in PageOnePanel.Controls) { if...
2
by: Adrian | last post by:
Hi everyone I have a web form where the validation works pefectly I copied the file, renamed it, and all of a sudden the validation stopped working(on the copied form). I have two panels on...
3
by: Martin | last post by:
Hi, I am implemeting a form in asp.net. The form is quite large and the validation is reasonably complex, so I have decieded to implement my own validation rather than use any custon...
12
by: raghav | last post by:
Hi I am working on ASP.NET 2.0. I am developing a website using Wizard control. Based on number of steps added, next, previous, finish buttons generate automatically. After running the...
24
by: Mike Hofer | last post by:
Please forgive the cross-post to multiple forums. I did it intentionally, but I *think* it was appropriate given the nature of my question. I'm working on an open source code library to help...
9
by: WT | last post by:
Hello, I have code created with .net 1.0 and migrated to 3.5. Form 2.0 the XslTransform class is obsolete and the vs2008 compiler generates warnings that these classes are absolete suggesting to...
0
by: Lars Eighner | last post by:
In our last episode, <004f629c$0$10265$c3e8da3@news.astraweb.com>, the lovely and talented mark4asp broadcast on comp.infosystems.www.authoring.html: I have not done this, not even on...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.