Question

Everything works fine if I work with validators separately. But if I try to work with CustomValidator along with any other validator, CustomValidator does not work.

For example I have one RequiredFieldValidator and one CustomValidator that checks if textbox length is five

enter image description here

If I leave first textbox empty and fill seconf textbox interestingly only RequiredFieldValidator is working:

enter image description here

But if I fill both textboxes, both validators work.

enter image description here

My question is that Why CustomValidator did not work on first scenario

Was it helpful?

Solution

I feel that you use default options with RequiredFieldValidator which makes it run on client side and your custom validator works only on server side. So when you don't fill in first field RequiredFieldValidator check it and block postback cuz it run on client side. Then your custom validator will never be noticed cuz postback was blocked. In order to make RequiredFieldValidator work on server side set EnableClientScript = false

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top