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).
as you can see, i've used the following controls here:
- ValidationSummary
- Label – Username
- Label – Password
- TextBox – Username
- TextBox – Password
- Button – Login
- RequiredFieldValidator – Username
- 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.
Now on each of the RequiredFieldValidator controls i'll set the ControlToValidate and 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.
good presentation
I am currently getting a viewstate error every time I try to submit either form on a page.
Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.
I am going to try some different things.
I need hellp
@Shadi,
what do you need help with?
Good tutorial, except the images seem to be missing…
pics are not visible
unable to use it
is it my net problem
yeah – lost all the images from the server a while ago.
sorry about that guys…
Swati, what exactly is the problem you”re having?