Disabling Validation for ASP.NET Server Controls
You might want to bypass validation under certain circumstances. For example, if you have a "Cancel" button or a navigation button on a page, the page should be able to post even if the user did not fill out all the validated fields correctly. You can set an ASP.NET server control to bypass validation on both the server and the client, or just on the client.
Security Note By default, the Web Forms page performs request validation to ensure that user input does not include script or HTML elements. You can disable this feature explicitly. For more information, see Scripting Exploits and Protecting Against Script Exploits in a Web Application.
Disabling Server-Side and Client Side Validation
You can specify that individual controls on a Web Forms page cause a postback without triggering a validation check.
To cause a specific control to bypass validation
- Set the control's CausesValidation property to false.
The following example shows how you can create a Cancel button that does not perform a validation check:
<asp:Button id="Button1" runat="server" Text="Cancel" CausesValidation="False"> </asp:Button>
You can also disable a validation control, so that it is not rendered to the page at all and no validation takes place using that control.
To disable a validation control
- Set the validation control's Enabled property to false.
Disabling Client-Side Validation Only
If you want to perform validation on the server but not on the client, you can set an individual validation control to not emit client-side script. This is useful if dynamic updating on the client creates problems with the layout of the page, or if you want to execute some server code before validation takes place.
To disable client-side validation
- Set the validation control's EnableClientScript property to false.