Dynamic Validator Help Please

Discussion in 'ASP .Net' started by =?Utf-8?B?TWlrZSBDb2xsaW5z?=, Nov 15, 2006.

  1. I have a form where I create dynamic controls at runtime. With this, I am
    adding a dynamic required field validator to each control as needed, but the
    validators are not firing when I click submit. The submit button was placed
    at design time and its causesvalidation property is set to true. Can someone
    tell me if something is missing from my code? Thank you.

    1. Code to add dynamic control works fine and I get the Id of the textbox
    control
    2. Then I see if a validator is required and add it...code below for that.
    3. I have the validator display set to none because I have a validation
    summary control, placed at design time, that I want to display. Is there
    something I need to do to make the validation summary know the required field
    validator is there, or something else I'm not thinking of? Thank you.

    if (required)
    {
    RequiredFieldValidator validator = new RequiredFieldValidator();
    validator.ID = "validator" + controlCount.ToString();
    validator.ControlToValidate = textBox.ID;
    validator.ErrorMessage = "Please fill out the textbox ";
    validator.Display = ValidatorDisplay.None;
    phContainer.Controls.Add(validator);
    }
     
    =?Utf-8?B?TWlrZSBDb2xsaW5z?=, Nov 15, 2006
    #1
    1. Advertising

  2. try adding:

    validator.Enabled =true;
    validator.EnableClientScript =true;
    validator.Visible =true;

    -- bruce (sqlwork.com)

    "Mike Collins" <> wrote in message
    news:...
    >I have a form where I create dynamic controls at runtime. With this, I am
    > adding a dynamic required field validator to each control as needed, but
    > the
    > validators are not firing when I click submit. The submit button was
    > placed
    > at design time and its causesvalidation property is set to true. Can
    > someone
    > tell me if something is missing from my code? Thank you.
    >
    > 1. Code to add dynamic control works fine and I get the Id of the textbox
    > control
    > 2. Then I see if a validator is required and add it...code below for that.
    > 3. I have the validator display set to none because I have a validation
    > summary control, placed at design time, that I want to display. Is there
    > something I need to do to make the validation summary know the required
    > field
    > validator is there, or something else I'm not thinking of? Thank you.
    >
    > if (required)
    > {
    > RequiredFieldValidator validator = new RequiredFieldValidator();
    > validator.ID = "validator" + controlCount.ToString();
    > validator.ControlToValidate = textBox.ID;
    > validator.ErrorMessage = "Please fill out the textbox ";
    > validator.Display = ValidatorDisplay.None;
    > phContainer.Controls.Add(validator);
    > }
     
    bruce barker \(sqlwork.com\), Nov 15, 2006
    #2
    1. Advertising

  3. Thanks for the reply, but still the validators do not seem to fire and the
    page is submitted. The validators are added the same time as the other
    controls, in the OnInit event. Maybe...can you not use validators added in
    the OnInit event?

    "bruce barker (sqlwork.com)" wrote:

    > try adding:
    >
    > validator.Enabled =true;
    > validator.EnableClientScript =true;
    > validator.Visible =true;
    >
    > -- bruce (sqlwork.com)
    >
    > "Mike Collins" <> wrote in message
    > news:...
    > >I have a form where I create dynamic controls at runtime. With this, I am
    > > adding a dynamic required field validator to each control as needed, but
    > > the
    > > validators are not firing when I click submit. The submit button was
    > > placed
    > > at design time and its causesvalidation property is set to true. Can
    > > someone
    > > tell me if something is missing from my code? Thank you.
    > >
    > > 1. Code to add dynamic control works fine and I get the Id of the textbox
    > > control
    > > 2. Then I see if a validator is required and add it...code below for that.
    > > 3. I have the validator display set to none because I have a validation
    > > summary control, placed at design time, that I want to display. Is there
    > > something I need to do to make the validation summary know the required
    > > field
    > > validator is there, or something else I'm not thinking of? Thank you.
    > >
    > > if (required)
    > > {
    > > RequiredFieldValidator validator = new RequiredFieldValidator();
    > > validator.ID = "validator" + controlCount.ToString();
    > > validator.ControlToValidate = textBox.ID;
    > > validator.ErrorMessage = "Please fill out the textbox ";
    > > validator.Display = ValidatorDisplay.None;
    > > phContainer.Controls.Add(validator);
    > > }

    >
    >
    >
     
    =?Utf-8?B?TWlrZSBDb2xsaW5z?=, Nov 15, 2006
    #3
    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. BillGatesFan
    Replies:
    2
    Views:
    571
    BillGatesFan
    Nov 4, 2005
  2. Replies:
    4
    Views:
    531
    Chris Uppal
    May 5, 2005
  3. KK
    Replies:
    2
    Views:
    626
    Big Brian
    Oct 14, 2003
  4. MuZZy
    Replies:
    7
    Views:
    1,780
    Mike Hewson
    Jan 7, 2005
  5. Replies:
    4
    Views:
    908
    Richter~9.6
    Feb 13, 2007
Loading...

Share This Page