RequiredFieldValidator and UserControl

  • Thread starter Thread starter DougS
  • Start date Start date
D

DougS

I'm attempting to put a RequiredFieldValidator next to a text box on a user
control. There will be a dozen of these controls added dynamically. At
runtime I get this error:

Unable to find control id 'txtValue' referenced by the 'ControlToValidate'
property of 'RequiredFieldValidator1'

Do validators only work on webforms?

Thanks,
Doug
 
The problem is that controls that are on user controls, get renamed at run
time, so that if you have more then one of that user control on the page,
that everything will be unique.

If the requiredfieldvalidator can't deal with this, it may be worth it to
run your own version. It's not too hard, and you will only need to do it
once since you are encapsulating all the functionality in your usercontrol.
 
Your textbox ID is prefixed with the user control name.
I'm pretty sure that's all your missing.
 
Back
Top