MSMVPS.COM
The Ultimate Destination for Blogs by Current and Former Microsoft Most Valuable Professionals.

ASP.Net 2.0 - How to use the new ValidationGroup property

Brian H. Madsen - .Net Powered by Caffeine

News

  • Home
  • Contact
  • About
  • RSS for Posts
  • Atom
  • All postings/content on this blog are provided "AS IS" with no warranties, and confer no rights. All entries in this blog are my opinion and don't necessarily reflect the opinion of my employer.

    ASP.NET Web Applications, Controls, Resources, Reviews

    Proud member of Perth Bloggers, a FeedBurner Network.

    Proud member of Aus/NZ MVPs, a FeedBurner Network.

    Proud member of CSharpZealots, a FeedBurner Network.

    Add to Technorati Favorites

    View Brian H. Madsen's profile on LinkedIn

    Windows Live Alerts

Feeds

With the release of ASP.Net 2.0 came a host of Validation features. In this series I'll be touching on those and show you how easily it now is to create validation for your forms.

In part 1 i'll be showing a new feature/property of existing validation tools - namely the ValidationGroup property. With this property you can now gather section specific validation together, so now there's no need to assess what to validate on PostBack.

In forms where you have several sections - some which might be dependant on others - some which might be individual and not be required. You can still validate these very easily should somebody input data into the fields.

For the purpose of illustrating this feature i'll be creating a very simple login form (not using any of the Login controls in ASP.Net 2.0).

 ValidationGroup - Login Form

as you can see, i've used the following controls here:

  1. ValidationSummary
  2. Label - Username
  3. Label - Password
  4. TextBox - Username
  5. TextBox - Password
  6. Button - Login
  7. RequiredFieldValidator - Username
  8. RequiredFieldValidator - Password

To group them all together in the same ValidationGroup you need to set the group name in the ValidationGroup property, which can be found at the very bottom of the property list if you sort it alphabetically.

I chose to use LoginForm as the ValidationGroup name. This will have to be done for each control you want to be grouped together.

ValidationGroup property - TextBox ValidationGroup property - password 

ValidationGroup property - Button ValidationGroup property - ValidationSummary

ValidationGroup property - RequiredFieldValidator ValidationGroup property - RequiredFieldValidator 2

Now on each of the RequiredFieldValidator controls i'll set the ControlToValidate and Display property.

ControlToValidate property

Display property

Now the reason for selecting None in the Display property is that i want the ErrorMessage value to display in the ValidationSummary.

Simple as that - you've now grouped the fields together with the ValidationSummary and both RequiredFieldValidator controls and can have several grouped validation rules in place on the same form.

ValidationGroup property - ResetForm ValidationGroup property - ResetForm


Posted Sep 10 2006, 12:13 AM by Brian Madsen

Comments

chandrashekhar rai wrote re: ASP.Net 2.0 - How to use the new ValidationGroup property
on 10-27-2006 4:05
good presentation


Copyright © is the original authors. Blog site is an independent site not sponsored by Microsoft. The Yoda blog server and the Brianna SQL server would like to thank www.ownwebnow.com and www.exchangedefender.com. They wouldn't be here and broadcasting without the generosity of Vlad Mazek and his companies.

Powered by Community Server (Commercial Edition), by Telligent Systems