dynamically creating controls, validators, using autopost back

Discussion in 'ASP .Net' started by =?Utf-8?B?TFU=?=, Mar 29, 2005.

  1. I query database,
    QuestionID | QuestionName | QuestionType
    1 | FirstName | TextBox
    2 | LastName | TextBox

    Loop
    Create TextBox
    Create RequiredFieldValidator

    Here is my problem.
    If user enters LastName, then FirstName is required.
    I can get LastName textbox to autopostback, but how do I create a sub that
    will capture the autopostback and then enable the requiredFieldValidator.
    I have many textboxes in the database so I need something that is generic?
    thanks
     
    =?Utf-8?B?TFU=?=, Mar 29, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?TFU=?=

    Lucas Tam Guest

    "=?Utf-8?B?TFU=?=" <> wrote in
    news::

    > If user enters LastName, then FirstName is required.
    > I can get LastName textbox to autopostback, but how do I create a sub
    > that will capture the autopostback and then enable the
    > requiredFieldValidator. I have many textboxes in the database so I
    > need something that is generic?


    Why don't you bind the requirefieldvalidator when you created it the
    first time?

    So your loop:

    Create Control
    Create Validator
    Bind Validator to Control

    On postback:
    Check validators
    Valid
    Continue
    Else
    Display Current Page


    --
    Lucas Tam ()
    Please delete "REMOVE" from the e-mail address when replying.
    http://members.ebay.com/aboutme/coolspot18/
     
    Lucas Tam, Mar 29, 2005
    #2
    1. Advertising

  3. I do bind when i create them.
    Loop
    Create textbox.id = 1
    Create requiredValidator.id = "req"&1
    requiredValidator.controlToValidate = 1
    requiredValidator.enabled = false

    I set enabled to false because the FirstName is not required UNLESS you you
    enter text into the LastName field. LastName is not required at all. In my
    example you can leave both first name and last name empty, but if you enter a
    last name, then you must enter a first name.
    So, I have lastname autopostback, (I can't figure out how to capture the
    autopost back to enable the fistname validator).
    Next,
    In my example I use FirstName and LastName, but in my database I have
    something like pub0, pub1, pub2, pub3, pub4
    so I wanted something generic to capture the postback, then I can strip the
    string, get the number, then enable the corresponding, requiredFieldValidator.

    "Lucas Tam" wrote:

    > "=?Utf-8?B?TFU=?=" <> wrote in
    > news::
    >
    > > If user enters LastName, then FirstName is required.
    > > I can get LastName textbox to autopostback, but how do I create a sub
    > > that will capture the autopostback and then enable the
    > > requiredFieldValidator. I have many textboxes in the database so I
    > > need something that is generic?

    >
    > Why don't you bind the requirefieldvalidator when you created it the
    > first time?
    >
    > So your loop:
    >
    > Create Control
    > Create Validator
    > Bind Validator to Control
    >
    > On postback:
    > Check validators
    > Valid
    > Continue
    > Else
    > Display Current Page
    >
    >
    > --
    > Lucas Tam ()
    > Please delete "REMOVE" from the e-mail address when replying.
    > http://members.ebay.com/aboutme/coolspot18/
    >
     
    =?Utf-8?B?TFU=?=, Mar 30, 2005
    #3
  4. =?Utf-8?B?TFU=?=

    Lucas Tam Guest

    "=?Utf-8?B?TFU=?=" <> wrote in
    news::

    > I set enabled to false because the FirstName is not required UNLESS
    > you you enter text into the LastName field. LastName is not required
    > at all. In my example you can leave both first name and last name
    > empty, but if you enter a last name, then you must enter a first name.
    >


    Maybe you could use a custom validator? Write some sort of custom
    validation routine that could your multiple cases.

    --
    Lucas Tam ()
    Please delete "REMOVE" from the e-mail address when replying.
    http://members.ebay.com/aboutme/coolspot18/
     
    Lucas Tam, Mar 30, 2005
    #4
    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. Ratman
    Replies:
    0
    Views:
    680
    Ratman
    Sep 14, 2004
  2. Derek Martin

    AutoPost Back List Boxes

    Derek Martin, Oct 20, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    404
    Derek Martin
    Oct 20, 2004
  3. Tony Doyle

    Autopost back and Blank Page

    Tony Doyle, May 17, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    426
    Tony Doyle
    May 18, 2005
  4. Jeffrey Todd
    Replies:
    1
    Views:
    4,136
    Peter Blum
    Jun 2, 2005
  5. TdarTdar

    Autopost Back, FormView, and Textbox Focus

    TdarTdar, Oct 12, 2005, in forum: ASP .Net Web Controls
    Replies:
    6
    Views:
    445
    Steven Cheng[MSFT]
    Nov 7, 2005
Loading...

Share This Page