Question Custom Validator

unknown

New member
Joined
Jun 18, 2012
Messages
1
Programming Experience
Beginner
Hi, I have a little bit of problem in my validation. I have added a custom validator and enabled= false. I have also added other validators too and it is all enabled.

It works like this.
When I enter a value in textbox and click the submit button, the code behind will validate all other basic validators. And when it is successful, custom validator will be enabled=true. And it will just return args.IsValid = false when the textbox value is not equals to the value in the database.

The thing is that the coding works. But only when I click the submit button the 2nd time. Everytime I load the website and tried to enter a value and click the button for the first time, arg.IsValid = false always does not trigger at all. So is this a bug or anything?

Thanks
 
The first time you press all the validators are run to enable your custom validator which is therefore excluded from the validation process. When you press the second time, the custom validator is enabled already and is therefore included in the validation process. You need either to permanently enable the custom validator (whether needed or not) or loop the validation so that it first enables the custom validator and ten runs again to include it.
 
Back
Top