Dynamic validation according to logged in user

No.of Views527
Bookmarked0 times
Downloads 
Votes0
By  questpond   On  16 Feb 2010 00:02:28
Tag : ASP.NET , How to
Dynamic validation according to logged in user
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

Many times we want certain set of validation to fire for some user and certain set of validation to fire for some other user. In the section we will see how we can achieve the same using Microsoft enterprise validation blocks.

I have collected around 400 FAQ questions and answers in WCF, WPF, WWF, SharePoint, design patterns, UML etc. Feel free to download these FAQ PDF’s from my site http://www.questpond.com Any feedbacks do email me at shiv_koirala@yahoo.com

The problem

There are times when you want validation according to the logged in user or customer. For instance in the below figure you can see we want different validation for both user. For one user we want that the customer code should be minimum 2 characters while for the other user we want it to be 5 characters.

Figure: - Logged in user

The Solution



Enterprise library helps us to solve this problem like a charm. To understand this article you need to once read basics of how to implement validation using VAB ( validation application blocks ).

To fire validation according to logged in user is a two step process.

Step 1
First you need to define two different rule set according to customer. For instance you can see in the below figure we have defined two validation. The first validation checks if the customer code is minimum two length while the second validation checks if the customer code is five length.

Step 2:- In step 2 we just need to call the validation according to user logged in using the “Validation” static class. The validate function of the validation static class have two parameters one is the customer object and the other is the rule name. So depending on logged in customer you can fire the rules on fly.

Thank you

Shivprasad Koirala

 
Sign Up to vote for this article
 
About Author
 
questpond
Occupation-
Company-
Member Type-Expert
Location-Not Provided
Joined date-24 Jun 2009
Home Page-
Blog Page-
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top