validator: one of two text boxes require a value

Discussion in 'ASP .Net Web Controls' started by smarty, Dec 3, 2009.

  1. smarty

    smarty Guest

    Hi,

    Please could I have some help with using the webform validation controls. I
    have found two problems when trying to use them.

    1. Although they do not show a visable error until they do the validation
    they still take up the space of a nomal text box on the form, so when placed
    next to the textbox control where they will show the error text on validation
    there is white space left where the text would be.

    Is there a way of ensuring the space is only taken up if the text is to be
    displayed?


    2. I have setup a webform using the required value validator control, which
    works fine for most fields on the form. I have two text boxes on the form
    that are for recording contact details. The customer only need to fill in
    one of the two contact details as their prefered contact method. So only one
    of the two text boxes must contain a value.

    I thought this must be a common situation in validating input but haven't
    found a way to acheive this using the validator controls. Is there a way?

    So far I have tried the following:

    a) Using a custom control. This works but I could only link this to one
    textbox. This is confusing for a user who types in to most fields and the
    error is removed prior to re-submitting the form but When the user types into
    the unlinked textbox the error is not removed.

    b) Using a compare control. It allows two controls to be specified but
    does not appear to allow custom validation to be used and the predefined
    operation is not suitable for enforing a required field.

    c) for now I have done all the validation in the submit button using
    labels, which works but the user has to submit to see if they have cleared
    the error, so it would be nicer to use one of the built in controls if this
    is possible.

    Thanks in advance for any help you can provide with this
    smarty, Dec 3, 2009
    #1
    1. Advertising

  2. 1) There is a display property on the validator that has an enumerated
    value. You have just described the Dynamic setting of that enumeration.

    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.basevalidator.display(VS.71).aspx


    2) Sounds like a useful custom validator. You should be able to build that
    guy no problem. Good news! It is much easier than it sounds.

    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator(VS.80).aspx


    --
    James VanDyne, MCPD
    Technical Consultant

    "smarty" <> wrote in message
    news:...
    > Hi,
    >
    > Please could I have some help with using the webform validation controls.
    > I
    > have found two problems when trying to use them.
    >
    > 1. Although they do not show a visable error until they do the validation
    > they still take up the space of a nomal text box on the form, so when
    > placed
    > next to the textbox control where they will show the error text on
    > validation
    > there is white space left where the text would be.
    >
    > Is there a way of ensuring the space is only taken up if the text is to be
    > displayed?
    >
    >
    > 2. I have setup a webform using the required value validator control,
    > which
    > works fine for most fields on the form. I have two text boxes on the form
    > that are for recording contact details. The customer only need to fill in
    > one of the two contact details as their prefered contact method. So only
    > one
    > of the two text boxes must contain a value.
    >
    > I thought this must be a common situation in validating input but haven't
    > found a way to acheive this using the validator controls. Is there a way?
    >
    > So far I have tried the following:
    >
    > a) Using a custom control. This works but I could only link this to one
    > textbox. This is confusing for a user who types in to most fields and the
    > error is removed prior to re-submitting the form but When the user types
    > into
    > the unlinked textbox the error is not removed.
    >
    > b) Using a compare control. It allows two controls to be specified but
    > does not appear to allow custom validation to be used and the predefined
    > operation is not suitable for enforing a required field.
    >
    > c) for now I have done all the validation in the submit button using
    > labels, which works but the user has to submit to see if they have cleared
    > the error, so it would be nicer to use one of the built in controls if
    > this
    > is possible.
    >
    > Thanks in advance for any help you can provide with this
    James VanDyne, Dec 4, 2009
    #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. Greg
    Replies:
    4
    Views:
    374
  2. news.frontiernet.net
    Replies:
    6
    Views:
    1,107
    news.frontiernet.net
    Apr 16, 2004
  3. Charles B. Summers
    Replies:
    6
    Views:
    717
    kayodeok
    Jun 28, 2004
  4. Stefan Mueller
    Replies:
    5
    Views:
    12,356
    jamesxa
    Jun 16, 2009
  5. Steve

    Use the same custom validator for 2 text boxes

    Steve, Aug 4, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    153
    Steve C. Orr [MVP, MCSD]
    Aug 4, 2005
Loading...

Share This Page