Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bypass validation for a button in ASP.NET?

I have an ASP.NET form that takes input from a user. There's a Submit button on the form and a button called Calc which does a calculation to populate a text field. The problem I'm having is that on the form I have a set of <ASP:REQUIREDFIELDVALIDATOR> validators and when the Calc button is pressed the form gets validated. I don't want the required fields to be validated when the Calc button is pressed, only the Submit button. Any way around this?

like image 946
Mark Allison Avatar asked Jun 17 '11 15:06

Mark Allison


People also ask

How to disable validation on button click in ASP net?

To prevent validation from being performed, set the CausesValidation property to false . You should set the CausesValidation property to false when you are using the PostBackUrl property to post back to a different page.

How can disable validation on button click in ASP NET MVC?

To disable validation when clicking a button, set the MVC Button. CausesValidation property value to false.

How to remove validation ASP net?

To disable a validation controlSet the validation control's Enabled property to false.

How to disable client side validation in ASP net?

To disable client-side validation, set the page's ClientTarget property to 'Downlevel' ('Uplevel' forces client-side validation). Alternatively, you can set an individual validator control's EnableClientScript property to 'false' to disable client-side validation for that specific control.


2 Answers

Set the CausesValidation property to false.

like image 196
Brandon Avatar answered Sep 19 '22 01:09

Brandon


<asp:Button runat="Server" ... CausesValidation="False" /> 

Button.CausesValidation (If I remember correctly).

like image 24
Brad Christie Avatar answered Sep 22 '22 01:09

Brad Christie