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

Viewed 53885

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?

8 Answers

You should use this

UseSubmitBehavior="False"

To disable validation in a specific control

Set the control's CausesValidation property to false.

<asp:Button id="Button3" runat="server"
  Text="Cancel" CausesValidation="False">
</asp:Button>

To disable a validation control

Set the validation controls Enabled property to false.

To disable client-side validation

Set the validation controls EnableClientScript property to false.

For More Info

Related