Click here to Skip to main content
Click here to Skip to main content

Dynamic Validation According to Logged in User

By , 18 Mar 2009
Rate this:
Please Sign up or sign in to vote.

Introduction

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

I have been writing and recording videos on architecture, design patterns, UML, enterprise blocks etc. You can view all my videos here. If you have any feedback, do email me at shiv_koirala@yahoo.com.

Other Application Blocks

  • Validation application blocks: This article explains the 16 steps you need to perform to do validations using VAB.
  • Client side validation: One of the shortcomings in VAB is that it does only server side validations. This article talks how we can leverage VAB for client side.
  • Policy Application blocks: This article talks about how to implement plug and play mechanism using Policy application blocks.
  • Logging application block: This article explains the 5 basic steps of how to use logging application blocks.
  • Data application: This article talks about the four steps you need to implement data application blocks.
  • Exception application block: This application talks about how we can use exception application blocks to log exception from project.
  • Unity application block: This application talks about Unity Application Block in DI and IOC.
  • UIP block: This article talks about Reusable Navigation and workflow for both Windows and Web using Microsoft UIP blocks.

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 validations for both users. 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 the basics of how to implement validation using VAB (validation application blocks). In case you are not aware of the basics, you can read the same from my previous article here.

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

Step 1

First you need to define two different rule sets according to customer. For instance, in the below figure, you can see that we have defined two validations. 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 the user logged in using the “Validationstatic class. The validate function of the validation static class has 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 the fly.

History

  • Updated with links of Other Application Blocks

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
Architect http://www.questpond.com
India India

I am a Microsoft MVP for ASP/ASP.NET and 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. Do visit my site for 
.NET, C# , design pattern , WCF , Silverlight
, LINQ , ASP.NET , ADO.NET , Sharepoint , UML , SQL Server  training 
and Interview questions and answers


Comments and Discussions

 
General45 Articles that lot of writing.... Pinmemberslemaryino25-Oct-08 20:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 19 Mar 2009
Article Copyright 2008 by Shivprasad koirala
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid