YouTip LogoYouTip

Prop Webcontrol Button Causesvalidation

## ASP.NET Button CausesValidation Property The `CausesValidation` property is a boolean attribute of the ASP.NET Web Server `Button` control. It determines whether page validation should be triggered when the button is clicked. By default, this property is set to `true`, meaning that clicking any button on the page will automatically execute all ASP.NET validation controls (such as `RequiredFieldValidator`, `CompareValidator`, `RegularExpressionValidator`, etc.) before submitting the form to the server. --- ## Definition and Usage When a user interacts with a form, there are scenarios where you want to bypass input validation. For example, if a user clicks a **Cancel**, **Reset**, or **Back** button, you want them to navigate away or clear the form without being blocked by "Field is required" validation errors. Setting the `CausesValidation` property to `false` prevents the validation controls from running, allowing the page to post back to the server immediately. --- ## Syntax ```xml ``` ### Property Values | Value | Description | | :--- | :--- | | `true` | **Default.** The page is validated when the button is clicked. | | `false` | The page is not validated when the button is clicked. | --- ## Code Examples ### Example 1: Bypassing Validation with a Cancel Button In this example, we have a required text field. If the user clicks the "Submit" button, validation is triggered. If they click the "Cancel" button, validation is bypassed, allowing the form to post back and execute the cancel logic. ```xml <%@ Page Language="C#" %> ASP.NET CausesValidation Example


``` --- ## Advanced Usage: Validation Groups If you want a button to validate only a specific set of controls rather than the entire page, you should use the `ValidationGroup` property in conjunction with `CausesValidation="true"`. By assigning the same `ValidationGroup` name to a group of input controls, their validators, and the triggering button, you can isolate validation behavior on complex pages with multiple forms. ### Example: ```xml ``` In this scenario, clicking the "Login" button will only trigger validation for the username field, completely ignoring the empty email field.
← Prop Webcontrol Button OnclienProp Webcontrol Adrotator Targ β†’