validating

  • Thread starter Thread starter Shahid Juma
  • Start date Start date
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
 
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.
 
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]);
 
Back
Top