The best way to validate UserControls

M

Max2006

Hi,

I have a user control that has a property named "Text"

Is there any way that I use a RequiredFieldValidator or CompareValidator to
validate my user control's value?

I tried it and I received this error:

Control 'cboCountry' referenced by the ControlToValidate property of
'valCountry' cannot be validated.

Thank you,
Max
 
M

Masudur

Hi,

I have a user control that has a property named "Text"

Is there any way that I use a RequiredFieldValidator or CompareValidator to
validate my user control's value?

I tried it and I received this error:

Control 'cboCountry' referenced by the ControlToValidate property of
'valCountry' cannot be validated.

Thank you,
Max

Hi...

i assume you have a control inside the usercontrol that receive input
from user and you do want to validate the input ...
here are the options you have...
1. add the requited field validator for the input in the usercontrol
rather that in the page...
2. validate the text using server side validation... (for this you
need to write a server side validation method...)

Thanks
Md. Masudur Rahman (Munna)
kaz Software Ltd.
www.kaz.com.bd
http://munnacs.110mb.com
 
S

Steven Cheng[MSFT]

Hi Max,

Yes, I agree with Masudur's opinion. Also, if you do want to make Validator
controls directly function against your ascx usercontrol, you can use the
"ValidationPropertyAttribute" class to define a property to be validatable
in your ascx control's code behind.

#ValidationPropertyAttribute Class
http://msdn2.microsoft.com/en-us/library/system.web.ui.validationpropertyatt
ribute(VS.80).aspx

Based on my test, through the intellisense not work, you can manually put
usercontrol's ID to validateor's "ControlToValidate" property and so far it
seems only server-side validation is working in this case.

Anyway, I think Masudur's suggested approaches are still the preferred ones
here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Hi Max,

Have you got any further idea on this or does the information helps you
some? Please feel free to post here if there is anything else we can help.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

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