Client side validation using Validation Application blocks

Questpond
Posted by in ASP.NET category on for Advance level | Views : 6157 red flag

Enterprise validation application provides us a ready made framework by which we can implement dynamic validation easily in our project. In case you are not aware of the basics you can watch my 20 minutes exclusive video on the same at http://www.questpondvd.com/EnterpriseApplicationBlock/EnterpriseApplicationBlock.html

By using enterprise validation blocks you can create validation in a dynamic fashion and the validations can be invoked depending on the user logged in. Now let’s understand one of the biggest drawbacks of the validation blocks and let’s see how we can address the same.
Title:        Client side validation using Validation Application blocks
Author:      Shivprasad Koirala 
Email:       shiv_koirala@yahoo.com
Language:    C#
Level:       Beginner
Description: Client side validation using Validation Application blocks

Client side validation using Validation Application blocks
 


Introduction
Problem
Broader level Solution
The Actual code

 

 

Introduction
 

Enterprise validation application provides us a ready made framework by which we can implement dynamic validation easily in our project. In case you are not aware of the basics you can watch my 20 minutes exclusive video on the same at http://www.questpondvd.com/EnterpriseApplicationBlock/EnterpriseApplicationBlock.html 

By using enterprise validation blocks you can create validation in a dynamic fashion and the validations can be invoked depending on the user logged in. Now let’s understand one of the biggest drawbacks of the validation blocks and let’s see how we can address the same.

I have writing and recording videos on design pattern, UML, estimation and lot more, you can see my work at http://www.questpond.com  . If you think in any way I should improve please email me with suggestions at shiv_koirala@yahoo.com.
 

Problem
 

The biggest drawback with validation application blocks is it does not generate client code. In other way to put is that all validations happen on the server side. From my perspective I think the application block developers have done it right. I mean they have defined a generic server side framework and left the implementation of the client validation to the respective clients like Windows, ASP.NET, etc.
 

Broader level Solution
 

So how do we solve the problem? First thing you can Google how much ever you want you will not find an easy way out for this. You need to develop your own adapter. That means you need to develop an adapter which will read the rules from the validation blocks API and create ASP.NET client side validator like required field, not null etc.

If you find a better solution do email me at shiv_koirala@yahoo.com
 

The Actual code


Ok, now we know the problem let’s see how we can solve the same. If you have run through the video given on the top you will understand that all validations are stored in web.config file. So somehow we need to browse through the web.config  file to get those validations. Once we get the validation we can then create ASP.NET validators depending on the validations present in web.config file.


If you see your web.config which has validators defined using validation application block it would look something as shown below. All validations are enclosed the validation tag. It’s a four step process to browse to get the validation.

Step 1:- Using the configuration source get the validation settings.

Step 2:- Using the validation settings get all the ruleset from the validation tag.

Step 3:- From the rule set get the rule set data collection.

Step 4:- Browse through the rule set data and generate the corresponding ASP.NET validators.
 

Below is the code for the above define steps.

 

In the final step we browse through the validator collection and generate the ASP.NET validators. You can use the type name to see which validator type it is. Using the ‘RangeValidatorData’ you can get the details of the validator data and you can generate the ASP.NET validators accordingly.

 

There are ranges of different validators provided in validation application blocks. Depending on the type you can create the corresponding type of ASP.Net validators at the client side. You can also generate windows validators accordingly.

Page copy protected against web site content infringement by Copyscape

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)