YouTip LogoYouTip

Prop Webcontrol Linkbutton Validationgroup

## ASP.NET LinkButton ValidationGroup Property The `ValidationGroup` property of the `LinkButton` control is used to specify a group of validation controls to validate when the `LinkButton` posts back to the server. This property is particularly useful in complex forms containing multiple input sections and multiple buttons, allowing you to trigger validation only for a specific subset of inputs rather than the entire page. --- ## Definition and Usage By default, when a button control (like `LinkButton`, `Button`, or `ImageButton`) is clicked, it triggers validation for all validation controls on the page. Setting the `ValidationGroup` property allows you to partition validation controls and their associated input controls into distinct groups. When a user clicks a `LinkButton` with a specified `ValidationGroup`, only the validation controls belonging to that same group will be executed. Common scenarios include: * **Multiple Forms on One Page:** A single page containing both a "Login" form and a "Newsletter Signup" form. * **Multi-Step Wizards:** Validating only the inputs of the current step before proceeding to the next. --- ## Syntax ```xml ``` ### Property Values | Property Value | Description | | :--- | :--- | | `group` | A string representing the name of the validation group to which this `LinkButton` belongs. Only validation controls with the matching `ValidationGroup` name will be triggered. | --- ## Code Example The following example demonstrates how to assign a `LinkButton` and a `RequiredFieldValidator` to the same validation group. In this setup, clicking the `LinkButton` will only trigger validation for the textbox `tb1` because they both share the validation group name `"valGroup1"`. ```xml <%@ Page Language="C#" %> LinkButton ValidationGroup Example


``` --- ## Key Considerations 1. **CausesValidation Property:** For the `ValidationGroup` to take effect, the `CausesValidation` property of the `LinkButton` must be set to `true` (which is the default value). If `CausesValidation` is set to `false`, no validation will occur regardless of the `ValidationGroup` setting. 2. **Case Sensitivity:** Validation group names are case-sensitive. Ensure that the `ValidationGroup` string on your `LinkButton` matches the `ValidationGroup` string on your validator controls exactly (e.g., `"valGroup1"` is different from `"ValGroup1"`). 3. **Empty ValidationGroup:** If you do not specify a `ValidationGroup` on a validator or a button, they belong to the default validation group (an empty string `""`). Clicking a button with no `ValidationGroup` defined will trigger all validators that also have no `ValidationGroup` defined.
← Prop Webcontrol Listitem EnablProp Webcontrol Linkbutton Tex β†’