How to turn required field validator off when selecting cancel button

wubblyjuggly picture wubblyjuggly · Aug 9, 2013 · Viewed 19.4k times · Source

I have a problem where my page has a required field validator, but I also want to use a 'cancel' button which will take the user back to the menu page using response.redirect("default.aspx");

Problem is the field validator keeps firing when you click the cancel button. How do you turn this off so the user can return to the menu page?

Answer

gzaxx picture gzaxx · Aug 9, 2013

Just add CausesValidation="false" to your button definition and it won't raise any validators:

<asp:Button ID="btnCancel" runat="server" Text="Cancel" CausesValidation="false" />