简体   繁体   中英

Bypass ASP.NET validation for onClick event of input

I have a <input> with an onclick event which checks for the Enter key. The called function may do a window.location redirect.

However, when I press the Enter key, it apparently fires off the page validation. So I see the validation messages for a split second.

How can I tell the page not to fire any of the validation events when the focus is in that <input>?

If it's an <asp:Button>, just set the CausesValidation property to false. But, I suspect that it's not actually the button that's causing it - but the form submit that happens as a resul of the Enter key.

If that's the case, you can use the client side API and set Page_ValidationActive = false; when focus changes.

Set ValidationGroup property of your validation controls. After that define ValidationGroup property to your button that you want to fire validation.

Also setting Causesvalidation property to false might help.

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