Home » none » ASP.NET Validation Controls. Friend or Foe?

ASP.NET Validation Controls. Friend or Foe?

This comes up on the message boards quite frequently.  The question normally starts out as, “How do I _________ with the _____ validation control?”  Or, if they are really looking for a solution rather than an implementation, they’ll ask how to do it with the validation controls instead of one specific control.

Then somewhere in the course of the thread someone will say something like, “it’s situations like that that have caused me to not use the 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.

Are there some situations that are more difficult than others?  Yes.  Should we not use them at all because of those situations?  Well, let’s do a cost benefit analysis:

Using validation controls gives us:

  • Client side AND server side validation by writing minimum code
  • Allows us to assign a validation to a specific control
  • Allows us to group validations and controls so that only specific validations fire for specific regions of the screen.
  • Gives us multiple, but consistent, ways of reporting the validation error back to the user.
  • I don’t have to learn JavaScript if I don’t want to.
  • Provides a custom validation control for the odd ball 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 multiple validations and multiple controls on the screen that do essentially the same thing because any specific control or validation can only belong to one validation group.

So far it looks like using validation controls would be much faster. 

Not using validation controls:

  • I’m stuck 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 screen.
  • I have to make sure I’m consistent in how I display the error from one screen to another.  This is particularly problematic when you are working with multiple developers.
  • All of the developers in my organization have to know javascript AND asp.net.
  • I can code validations any way I want.
  • I might get greater code re-use.

Sorry, I’m not seeing a big advantage here.  In fact, I’ve been coding ASP.NET applications and teaching others to use ASP.NET 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 argue that they were not the appropriate solution.  This is especially true now that we have the ability to group the controls and validations.

So, here’s the challenge.

Anyone that has a situation they think will not work using the existing set of validation controls is welcome to post a comment with their specific situation.  Maybe someone can change my mind.

del.icio.us Tags: ,

Technorati Tags: ,

Related Post

  • jQuery Dialog – With Validation ControlsjQuery Dialog – With Validation Controls Chances are, you’ll eventually want to use a dialog box in combination with some form elements, and when you do, you’ll probably want to implement some validation. True, there are some […]
  • DotNetNuke Modules – Creating Base ModulesDotNetNuke Modules – Creating Base Modules Now that we have DotNetNuke installed into Visual Studio we can go ahead and create our first modules. Actually, creating the modules is pretty simple. But it is even easier to do it […]
  • Response.Redirect() executes too soon on the Server.Response.Redirect() executes too soon on the Server. I've seen this question a couple of times in various situations. The first involves Javascript and the second involves server side code. Both are caused by a misunderstanding of what […]
  • Why ASP.NET Changes Don’t Change AnythingWhy ASP.NET Changes Don’t Change Anything Has this happened to you? You make a change to a codebehind file or a web.config file and you rerun the application to see the effect and there is no change from the previous […]
  • ASP.NET Response.Redirect() and JavaScriptASP.NET Response.Redirect() and JavaScript Yesterday we covered issues surrounding using ASP.NET's Response.Redirect in server side code. We noted that not handing it correctly could prevent code from running on the server that we […]

About Dave Bush

Dave Bush is a Full Stack ASP.NET developer. His commitment to quality through test driven development, vast knowledge of C#, HTML, CSS and JavaScript as well as his ability to mentor younger programmers and his passion for Agile/Scrum as defined by the Agile Manifesto and the Scrum Alliance will certainly be an asset to your organization.

One Pingback/Trackback