Sunday, November 23, 2008

ASP.NET Validation Controls. Are They Helpful or Not?

ASP.NET Validation Controls. Are They Helpful or Not?

by Dave Bush



This is something I see on the message boards quite a bit. It usually starts with something like, "How can I _______ with the _______ validation control?" Or, if they are really looking for an explanation rather than an implementation, they'll ask how to do it with the validation controls instead of one specific control.



Eventually someone will be frustrated enough to say, "that's exactly why I never use validation controls..." Most recently, it was an MVP who seems to be everywhere. {But, an answer like this makes me question every answer he's likely to give on the forum.|But an answer like this makes me wonder about any answer he's likely to give on the forum.



Are some situations more difficult than others? Absolutely. Should this really cause us to discount them altogether? Well, let's do a cost benefit analysis:

Here are the advantages of using validation controls:



The ability to write minimum code using client side AND server side validation.

* Ability to assign a validation to a specific control

* Only particular validations will fire for specific areas of the screen by grouping validations and controls

* Gives us several consistent methods to report the validation error back to the user.

* It is unnecessary to learn JavaScript

* Provides a custom validation control for the rare case which conforms to how the other validation controls work so that all we have to do is write the validation but displaying the error message, firing the validation, etc is left to the framework.

* I might have to have several validations and several controls on the screen that do the very same thing for the reason that any specific control or validation can only belong to one validation group.



With these points, It seems as if using validation controls would be much faster.

What if we don't use validation controls?



I must spend my time writing validations by hand myself or using some other framework (one I probably wrote myself and therefore isn't tested as well)

* I have to write code to display the error on the computer screen.

* I must be consistent in how the error is displayed from one screen to another. Especially when you are working with several different developers, this could be particularly difficult.

* Each of the developers in my organization have to know asp.net AND javascript..

* I can choose however I want to code validations.

* My code re-use might be greater.



I am not really seeing the advantage here. Actually, In my own experience with ASP.NET applications since beta 1 of version 1.0, I've yet to see a situation where the validation controls wouldn't work or where anyone could debate that they wouldn't be the right answer. This is even more true now that we can group the controls and validations.

So, here's the challenge.



Find a situation you think will not work using the existing set of validation controls and post a comment with your specific situation.. Maybe someone can change my mind.



del.icio.us Tags: asp.net , validation controls





About the Author

Dave answers ASP.NET related questions at .NET Answers and runs a Web hosting company at My Win Hosting.

Get Free Articles for your web site, newsletter, or ezine at the Free Article Headquarters.

AddThis Feed Button

0 comments:

Post a Comment

VIDEO

Loading...

NEWSFEED

Free content by Fresh Content.net

TOOLS & PACKAGES

Sign up for PayPal and start accepting credit card payments instantly. Show my IP address location HTML code Oneline users :

BLOGGER

PRODUCT & RESOURCES

JUST A CLICK AWAY