简体   繁体   中英

CustomValidator not working with other validators

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

在此处输入图片说明

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

在此处输入图片说明

But if I fill both textboxes, both validators work.

在此处输入图片说明

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM