Click here to Skip to main content
5,785,816 members and growing! (18,412 online)
Email Password   helpLost your password?
Web Development » ASP.NET » General     Beginner License: The Code Project Open License (CPOL)

Client side validation using Validation Application blocks

By Shivprasad koirala

Client side validation using Validation Application blocks
Windows, ASP.NET, Architect

Posted: 14 Oct 2008
Updated: 23 Oct 2008
Views: 6,651
Bookmarked: 29 times
Note: This is an unedited reader contribution
Announcements
Loading...



Search    
Advanced Search
Sitemap
18 votes for this Article.
Popularity: 3.89 Rating: 3.10 out of 5
5 votes, 27.8%
1
4 votes, 22.2%
2
2 votes, 11.1%
3
2 votes, 11.1%
4
5 votes, 27.8%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Table of Contents

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 here.

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 here. 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.

Click to enlarge

Below is the code for the above defined steps.

Click to enlarge

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.

Click to enlarge

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Shivprasad koirala


I am currently a CEO of a small E-learning company in India. We are very much active in making training videos , writing books and corporate trainings. You can visit about my organization at www.questpond.com and also enjoy the videos uploaded for Design patter, FPA , UML , Project and lot. I am also actively involved in RFC which is a financial open source madei in C#. It has modules like accounting , invoicing , purchase , stocks etc.
Occupation: Architect
Company: http://www.questpond.com
Location: India India

Other popular ASP.NET articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 5 of 5 (Total in Forum: 5) (Refresh)FirstPrevNext
GeneralCode?memberLordGentle6:45 26 Oct '08  
GeneralImages are blurrymemberTodd Smith19:40 23 Oct '08  
GeneralRe: Images are blurrymemberShivprasad koirala22:31 23 Oct '08  
GeneralRe: Images are blurrymvpNishant Sivakumar3:26 24 Oct '08  
GeneralRe: Images are blurrymemberRuslanCanada12:05 24 Oct '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 23 Oct 2008
Editor: Deeksha Shenoy
Copyright 2008 by Shivprasad koirala
Everything else Copyright © CodeProject, 1999-2009
Web20 | Advertise on the Code Project