validating

S

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
 
T

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.
 
S

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]);
 

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

Top