Dynamic Validator Help Please

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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);
}
 
try adding:

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

-- bruce (sqlwork.com)
 
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?
 
Back
Top