Using ValidationGroups in Dynamic Data Prior to .NET 4.0
In ASP.NET webform pages, validation groups create sets of controls that are validated separately from other controls. For example, on the same page, one set of controls could be validated when inserting a new product, while a separate group of controls are validated when searching for a product. More information is available here.
The current (.NET Framework 3.5 SP1) Dynamic Data controls do not have the ValidationGroup property. This is problematic when there are different sets of DynamicValidator and ValidationSummary controls on the same page. For example, controls for managing products and product subcategories might be on the same page and each set of controls would have validation (required fields, date format, etc.). But without the ValidationGroup property, validation errors in one set of controls would show error messages in both ValidationSummary controls.
Starting with the .NET 4.0 Framework, ValidationGroup will be a property of the Dynamic Data controls. However it is possible to use validation groups without the entire 4.0 framework. Here’s how.
First, download and unzip ASP.NET Dynamic Data Preview 4.
Second, from a Dynamic Data web application remove the existing references to System.ComponentModel.DataAnnotations.dll and System.Web.DynamicData.dll. Then add references to the following assemblies, which are in the DynamicDataPreview4\DynamicDataVNextSamples\CommonFiles directory.
- Microsoft.Web.Extensions.dll
- System.ComponentModel.DataAnnotations.dll
- System.Web.DynamicData.dll
You’ll have to decide if the risk of using preview assemblies is worth the benefit of extra functionality. Personally, I’ve had no problems with the preview assemblies and would use them until I upgraded to the 4.0 framework.
Third, you will need to update the version number of the System.Web.DynamicData assembly in the web.config file. The version number must match the one being referenced. In the system.web/compilation/assemblies node, change
<add assembly=”System.Web.DynamicData, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35″/>
to
<add assembly=”System.Web.DynamicData, Version=99.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35″/>
And in the system.web/pages/controls node change
<add tagPrefix=”asp” namespace=”System.Web.DynamicData” assembly=”System.Web.DynamicData, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35″/>
To
<add tagPrefix=”asp” namespace=”System.Web.DynamicData” assembly=”System.Web.DynamicData, Version=99.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35″/>
Last, add the ValidationGroup property to the Dynamic Controls. Attached to this post is an example page with two sets of Dynamic Data controls. One set is for products, the other for product subcategories. The DynamicField, CommandField, ValidationSummary and DynamicValidator controls are in their respective ValidationGroup, which as expected eliminates cross validation.