Technodrone

there's some good in this world, Mr. Frodo... and it's worth fighting for.

  Home  |   Contact  |   Syndication    |   Login
  15 Posts | 2 Stories | 37 Comments | 0 Trackbacks

News

Article Categories

Archives

Post Categories

Image Galleries

agile development

Code hacks

Face Book Profile

LinkedIn Profile

Recommended Products

The built in validator controls can remove the tedious code needed to traditionally check user input and I have found that using them in very simple pages is a great time saver but using them on a complex page  where valid input varies depending on any number of factors it is better to verify input programmatically, tell the user if there were any problems, tell them what to do, tell them if there were any database errors , or if they successfully completed their transaction.   Whenever I create UI pages or classes I always pre-plan for  what I call "user messages".   I even program these into interfaces so they are required in any implementing classes.  Example if a "Save" is successful in an object pass a boolean of true if not successful  I will tell the user and also write it an error log.  I have read that validation controls keep you from having to do things like regex functions to see if a string contains a Phone#.  I can write the function to check this and put it in a class and call it when needed rather than having to put the control on each page needing Phone#.   I work in an environment where validation can change monthly or even during a part of the month (close of month) so I don't use the validation controls unless I think the requirements for input are not likely to change. 
I have found it most flexible to create a stringbuilder object and append user/error messages to it.  I can then display the messages in a variety of ways depending on a variety of conditions.  I find this is easier to change if the user decides that a phone# is only required for citizens of Arkansas but not for Missouri and then only in certain area codes.
My co-workers don't agree with me. They strive to make the built-in validators work at all cost, and want me to conform.  I am just not feelin it.

posted on Wednesday, August 13, 2008 11:51 AM

Feedback

# re: ASP.NET Validation Controls- Good but sometimes I need more 8/15/2008 3:00 PM Mike Ellis
It's true that sometimes the standard client-side validators just can't handle the task at hand. They are great for simple validations like required fields, regexes, etc., but not for complex validation logic.

What we're doing is kind of a hybrid approach. We do client-side validation when it can be done, but then we also do server-side validation of certain business rules. When a server-side validation fails, we are invalidating one of the client-side validator controls (requiredFieldValidator.IsValid = false) and setting its errormessage property appropriately. That way, error messages display the same way whether the validation happends client-side or server-side. The only difference is the postback. In this way, you could use the controls to display the error, but use your classes to do the validation.

# re: ASP.NET Validation Controls- Good but sometimes I need more 8/27/2008 3:38 PM i hate .net
I hate it when you have to press the button more than once to see the error message after a postback validation. So I abandoned the validation controls and programmatically validate and display error messages with a label.

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: