Home All Groups Group Topic Archive Search About
Author
9 Aug 2006 8:01 PM
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?

Author
10 Aug 2006 2:45 PM
marss
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?

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 == ""));
}