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

dynamically adding validation controls

P: n/a
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.
Nov 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"Jack" <Ja**@discussions.microsoft.com> wrote in message
news:94**********************************@microsof t.com...
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.

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.