dynamically adding validation controls

G

Guest

Hi,

I have a page with a repeater control that contains textboxes. I'm trying
to create a validation class that is called by my page. A method in this
class iterates through all the controls on the page. On encountering a
TextBox control, it looks at the ID to discern the field the TextBox
represents, and then creates the appropriate validation controls and adds
them to the page. The controlToValidate property of each validation control
is the ClientID of the current TextBox in question.

When I run the page I get an error such as: Unable to find control id
'SchoolsRepeater__ctl0_txtStudent_LastName' referenced by the
'ControlToValidate' property of ''.

Of course the same type of error will occur when I use the control.ID as the
controltovalidate property.

Currently this Validation class method is called on the page at the end of
the page_load method. I've also tried putting it in the OnInit method, to no
avail.

Suggestions? Thanks.

Jack.
 
P

Peter Blum

The basic problem is that the ControlToValidate property requires the ID of
the other control, not the ClientID. This means that both the validator
control and its textbox must be in the same naming container. (Each row of a
Repeater is a different naming container.) So be sure to put the validator
into each row and use the ID property.

FYI: I wrote a replacement to Microsoft's validators, "Professional
Validation And More" (http://www.peterblum.com/vam/home.aspx). Its 22
validators allow attaching controls that are in other naming containers.
There are numerous enhancements in Professional Validation And More to
address the limitations of the Microsoft validators and give users the
features they've requested but haven't found in Microsoft's validators.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 

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,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top