Validation of 2 Textboxes

R

RChase

Here is my situation:

I have two fields (let's call them FieldA and FieldB). If FieldA contains a
value then FieldB cannot, and if FieldB has a value FieldA cannot.

Is there a way using the Validation controls to check for this?
 
M

marss

RChase напиÑав:
Here is my situation:

I have two fields (let's call them FieldA and FieldB). If FieldA containsa
value then FieldB cannot, and if FieldB has a value FieldA cannot.

Is there a way using the Validation controls to check for this?

Use CustomValidator. Add handler for ServerValidate event.

Something like this:

private void CustomValidator1_ServerValidate(object source,
System.Web.UI.WebControls.ServerValidateEventArgs args)
{
args.IsValid = ((FieldA.Text == "" && FieldB.Text != "") ||
(FieldA.Text != "" && FieldB.Text == ""));
}
 

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,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top