Home All Groups Group Topic Archive Search About
Author
10 Jun 2005 7:01 PM
Shahid Juma
Hi,

I am reading an XML file and creating a form (ie. putting text
fields/radio buttons, etc.).

I would like to validate the Text Fields but the RequiredValidator
requires me to specify the name of the field.  My text fields are
dynamically created .

Any help would be greatly appreciated. I am using C#.

Shahid

Author
10 Jun 2005 7:52 PM
Teemu Keiski
Hi,

you can still assign those dynamically created controls an ID and pass this
ID also to the validator control. That way it knows which control to
validate.

If you have some sort of repeating happening and you don't use built-in
databound controls such as repeater helping you, you'd probably need to
manage the ID naming yourself, means that add an row index to the ID or
something so that they are kept unique.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
Are all your drivers up to date? click for free checkup

Author
14 Jun 2005 5:43 PM
Shahid Juma
I was able to generate it dynamically and also tried to generate the
RequiredFieldValidator, but it doesn't validate.

This is what I have:

req[x] = new RequiredFieldValidator();
req[x].ID = "score_" + (i+1) + "_" + (x+1);
req[x].ControlToValidate = "score_" + (i+1) + "_" + (x+1);
req[x].ErrorMessage = "Please enter the score";
PlaceHolder2.Controls.Add(req[x]);

Bookmark and Share