In part 1 of Validating Drop Downs In ASP.NET we discussed how to use the Required Field Validator to provide responsive client side validation of form controls without directly writing JavaScript. In this post we are going to discuss how to allow postbacks without validating form controls.
While that sounds contradictory to the goal of validation I assure you it is not. Consider our scenario from last time:
--please select one-- Apples Oranges
In addition to allow your site users to select either apples or oranges you also have a submit button to send their result back to the server.
So far everything is working just fine. You users can select a fruit and send their choice to the web server for processing. But what if you need a cancel button that also needs to postback to the server?
This is where the CausesValidation button property comes in.
By default all buttons CausesValidation property is true, so by changing it to false we can all only specific buttons to postback without the form controls necessarily validating.
Allowing the form to postback without validation is as simple as adding the CausesValidation=”false” property to each button that needs to circumvent validation.