Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to validate a control that might be empty

Reply
Thread Tools

How to validate a control that might be empty

 
 
Alan Silver
Guest
Posts: n/a
 
      06-19-2006
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)
 
Reply With Quote
 
 
 
 
Winista
Guest
Posts: n/a
 
      06-19-2006
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" <alan-> wrote in message
news:...
> 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)



 
Reply With Quote
 
 
 
 
=?Utf-8?B?RGVtZXRyaQ==?=
Guest
Posts: n/a
 
      06-19-2006
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)
>

 
Reply With Quote
 
Alan Silver
Guest
Posts: n/a
 
      06-19-2006
In article <>, Alan Silver
<alan-> 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)
 
Reply With Quote
 
Alan Silver
Guest
Posts: n/a
 
      06-19-2006
In article <5608E2DE-B90B-4DC3-84C9->, Demetri
<> 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)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
DetailsView ASP Control and an empty field not an empty record. ButlerDJIAM ASP .Net 0 11-09-2006 06:40 PM
validate if dropdownlist is empty js ASP .Net 2 04-23-2006 03:16 PM
CustomValidator doesn't validate on a textbox that is empty Ned ASP .Net 2 02-09-2004 07:49 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57