Validation of 2 Textboxes

Discussion in 'ASP .Net Web Controls' started by RChase, Aug 9, 2006.

  1. RChase

    RChase Guest

    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?
    RChase, Aug 9, 2006
    #1
    1. Advertising

  2. RChase

    marss Guest

    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 == ""));
    }
    marss, Aug 10, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Colin Mackay
    Replies:
    0
    Views:
    2,678
    Colin Mackay
    Jun 25, 2003
  2. Russ
    Replies:
    3
    Views:
    904
  3. =?Utf-8?B?bWc=?=
    Replies:
    1
    Views:
    633
    Ashish M Bhonkiya
    May 18, 2004
  4. Alphonse Giambrone

    Validation for Two Textboxes

    Alphonse Giambrone, Oct 21, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    487
    Alphonse Giambrone
    Oct 21, 2004
  5. Keith G Hicks
    Replies:
    1
    Views:
    343
    Mark Rae [MVP]
    Feb 23, 2008
Loading...

Share This Page