简体   繁体   中英

ASP.Net Webforms: Can a RequiredFieldValidator be listened to? (Event)

Basically is there a way to hook into when a RequiredFieldValidator does what it does? Like validator.ValidationCompleted ?

Normally for script controls, you can create an expose events so that you can listen to them from other controls, and I was asked if this is possible for the build in validation controls in asp.net but couldn't come up with a good way to do this. I was hoping that there is something built in that fires after a validator has completed it's task that can be captured client side.

Validators tend to operate client-side by default (EnabledClientScript defaults to True), but if you choose to push them server-side you simply need to look at the IsValid property of the Page to see if the validators were successful. You can look validator-by-validator server-side to determine which validators failed by iterating through the Page.Validators collection and checking each Validator for IsValid. If you wish you could change the way client-side validation is handled through this: http://msdn.microsoft.com/en-us/library/aa479045.aspx#aspplusvalid_clientside

Short answer: No.

You'll have to use a CustomValidator for client-side script you want to run when validation occurs. See the "ClientValidationFunction" property. Other options include 3rd party validation controls, or rolling your own.

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