Dynamic Validator Help Please

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);
}
 
B

bruce barker \(sqlwork.com\)

try adding:

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

-- bruce (sqlwork.com)
 
G

Guest

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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top