Manual Validate() call always returns IsValid=true

J

Jon Davis

This is always returning True, even when fields are empty. Why?


private bool ValidatePageOne() {
bool ret = true;
foreach (Control ctrl in PageOnePanel.Controls) {
if (ctrl.GetType().IsSubclassOf(typeof(BaseValidator))) {
((BaseValidator)ctrl).Validate();
if (!((BaseValidator)ctrl).IsValid)
ret = false;
}
}
return ret;
}
 
J

Jon Davis

I should note:

Before doing this manually (using the regular page validation instead) it worked fine. Also, I am stepping through the code and the Validator controls are being found and Validate() is being run. Some of these are RequiredFieldValidators. But the textboxes they are associated with are empty, and yet IsValid is returning True! Why?

Jon

This is always returning True, even when fields are empty. Why?


private bool ValidatePageOne() {
bool ret = true;
foreach (Control ctrl in PageOnePanel.Controls) {
if (ctrl.GetType().IsSubclassOf(typeof(BaseValidator))) {
((BaseValidator)ctrl).Validate();
if (!((BaseValidator)ctrl).IsValid)
ret = false;
}
}
return ret;
}
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top