Prop Webcontrol Button Validationgroup
## ASP.NET Button ValidationGroup Property
The `ValidationGroup` property of the ASP.NET Button control allows you to group validation controls together on a web page. By assigning a specific validation group to a Button, you can specify that only the validation controls within that same group should be evaluated when the button is clicked and posts back to the server.
This property is highly useful in scenarios where a single page contains multiple forms or distinct logical sections (for example, a login form and a registration form on the same page) and you want to prevent validation in one section from blocking submissions in another.
---
## Definition and Usage
* **Purpose:** Specifies the group of validation controls to validate when the `Button` control posts back to the server.
* **Common Scenario:** Used when a page contains multiple buttons and input fields, and you only want to validate a specific subset of inputs associated with the clicked button.
---
## Syntax
```xml
```
### Property Values
| Property | Type | Description |
| :--- | :--- | :--- |
| **ValidationGroup** | `String` | The name of the validation group to trigger when the button is clicked. This must match the `ValidationGroup` property of the target validation controls. |
---
## Code Example
The following example demonstrates how to partition validation on a single page using the `ValidationGroup` property.
In this scenario, we have two separate sections: **Group 1** and **Group 2**. Clicking the button in Group 1 will only trigger validation for the textbox in Group 1, leaving Group 2 unaffected, and vice versa.
```xml
<%@ Page Language="C#" %>
ASP.NET Button ValidationGroup Example
```
---
## Key Considerations
1. **CausesValidation Requirement:** The `ValidationGroup` property only takes effect if the Button's `CausesValidation` property is set to `true` (which is the default value). If `CausesValidation` is set to `false`, no validation will occur regardless of the `ValidationGroup` setting.
2. **Matching Names:** The string assigned to the `ValidationGroup` property of the Button must exactly match the `ValidationGroup` property of the input validators (e.g., `RequiredFieldValidator`, `CompareValidator`, etc.) you wish to trigger.
3. **Default Group:** If no `ValidationGroup` is specified on either the validators or the button, they all belong to the default validation group. Clicking any standard validation button will trigger all validators on the page that do not have an explicit group assigned.
YouTip