By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,543 Members | 2,246 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,543 IT Pros & Developers. It's quick & easy.

Dynamic Validator Help Please

P: n/a
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);
}
Nov 15 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
try adding:

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

-- bruce (sqlwork.com)

"Mike Collins" <Mi*********@discussions.microsoft.comwrote in message
news:49**********************************@microsof t.com...
>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);
}

Nov 15 '06 #2

P: n/a
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" <Mi*********@discussions.microsoft.comwrote in message
news:49**********************************@microsof t.com...
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);
}


Nov 15 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.