473,408 Members | 2,009 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,408 software developers and data experts.

Validator Application Block

I'm using the Microsoft Validator Application Block with attributes to
assign validators to various fields in a class. It's pretty straightforward:

// public fields used for brevity

[StringLengthValidator(1,50)]
public string someValue;

[StringLengthValidator(1,50)]
public string someOtherValue;

[???????]
public string yetAnotherValue;

My question is, how would I assign a validator to "yetAnotherValue" ONLY IF
"someOtherValue" is not null? Is there a conditional operator that can point
to another field?

Validating individual fields is simple enough, I just don't know how to do a
conditional validation.

Thanks.

Sep 29 '08 #1
1 1537
Found the answer for anyone who might be able to use it. The SelfValidation
attribute allows for custom validation logic.

[HasSelfValidation]
public class Customer
{
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}

[SelfValidation]
public void Validate(ValidationResults results)
{
if (string.IsNullOrEmpty(_name))
{
results.AddResult(
new ValidationResult(
"Name cannot be null.",
this,
"Name",
null,
null
)
);
}
}
}

"Scott Stark" <em***@scottstark.comwrote in message
news:OO****************@TK2MSFTNGP02.phx.gbl...
I'm using the Microsoft Validator Application Block with attributes to
assign validators to various fields in a class. It's pretty
straightforward:

// public fields used for brevity

[StringLengthValidator(1,50)]
public string someValue;

[StringLengthValidator(1,50)]
public string someOtherValue;

[???????]
public string yetAnotherValue;

My question is, how would I assign a validator to "yetAnotherValue" ONLY
IF "someOtherValue" is not null? Is there a conditional operator that can
point to another field?

Validating individual fields is simple enough, I just don't know how to do
a conditional validation.

Thanks.
Sep 29 '08 #2

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

Similar topics

16
by: Dave | last post by:
Hello all, I'm getting a strange error when I try to validate my page(s). The error occurs when I use SELECT and INPUT tags inside of the FORM tag. I am trying to use the XHTML 1.0 Strict...
5
by: johnleemk | last post by:
I download the source for W3C's validator from http://validator.w3.org/source/ to validate pages on my own server. I commented a block of code that checks for non-public hosts so the validator...
5
by: Ney André de Mello Zunino | last post by:
Hello. Running the following document through the W3C's validator, returns the error: "end tag for "body" which is not finished." <!-- Start of sample document --> <?xml version="1.0"...
8
by: pmud | last post by:
Hi, I am using a compare validator in asp.net application(c# code). This Custom validator is used for comparing a value enterd by the user against the primary key in the SQL database. IF the...
40
by: VK | last post by:
Hi, After the response on my request from W3C I'm still unclear about Tidy vs. Validator discrepansies. That started with <IFRAME> issue, but there is more as I know. Anyway, this very basic...
9
by: Joshua Franco | last post by:
I am having trouble with the W3C html validator. The page: http://www.acmlm.org/beta/ is listed by the validator as not valid html 4.01 strict. I belive this page to be correct though. The...
10
by: Ken1 | last post by:
Is there a way to know if the user has javascript on? Also, is it a good idea to validate all input in js and php or will this slow down the website?
10
by: Barry L. Camp | last post by:
Hi all... hope someone can help out. Not a unique situation, but my search for a solution has not yielded what I need yet. I'm trying to come up with a regular expression for a...
37
by: Prisoner at War | last post by:
Actually, it doesn't have to be a blockquote...but I'm at my wits' end: I want to make bold several lines of text which have a pair of <br /tags between them...seems like the <b></bdo not "carry...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.