Scott Hanselman

Sheesh, ScottGu, just buy this company already...

February 14, '04 Comments [3] Posted in ASP.NET | Javascript | Internationalization | Bugs | Tools
Sponsored By

I briefly mentioned this 3rd party tool once before, but as I'm using it daily and for the last 4 months, I wanted to post more on it.  (Note: I'm just doing this 'cause I dig it.  I'm not meaning to sound like a shill, but you know me, if it's cool, I tell you.  If it sucks, I say it loud.)

Every once in a while you come upon some cool controls for ASP.NET that you just have to spread the word.  Andy Smith's stuff is like that, you know, and now he works with Robert McLaws at Interscape. Just clever, simple, elegant and few moving parts.  When I find a set of controls that give me elegant and powerful functionality I typically RIP them apart to find out how they did it and how I can learn from them. 

So the fellow I want to talk about is Peter Blum, and the ASP.NET Toolkit is the Validation and More package.

Validation Sucks

We write banking sites and one of the things that is the most time consuming and irritating is the client side validation code.  Banking sites typically have VERY complex business rules that need to be represented in the browser...things like "If this index in this drop down is selected, make sure this checkbox can be checked and require this text in this text box, else show an alert box."  It's the kind of code that you COULD write in custom JavaScript, but getting it to work on every browser is a hassle.  Also, you might write a bunch of code that shows the error messages in an alert box, but then the client says, "this is great, but put it in a table at the end of the page" or "put a dot by each text box that needs to be validated" or "turn each control red when there's an error" or worse, "all of the above."

Microsoft ships 5 validation controls with ASP.NET and they are OK, and produce some pretty basic JavaScript.  Rather than working from these meager beginnings, Peter starts from scratchNow, seriously, pause and drink that in.  The VAM (Validation and More) controls are NOT "more ASP.NET Validation Controls" - they are a complete and total framework in and of themselves.  It's a whole new way of thinking about validation in ASP.NET.  He's basically written a Validation/Action engine in cross-browser Javascript. 

Each of the VAM controls (there's 22) can be manipulated in the ASP.NET Design Mode surface with property pages.  So, for example, you can drop a MultiConditionValidator on the page, add a TextRequiredValidator and a RegularExpressionValidator and associate them with one or more controls like TextBoxes, or Combos.  Then here's the magic: On the client-side an array of actions is generated.  When the form is about to be submitted client-side, VAM uses the powerful eval()-uation features of JavaScript to dynamically validate the page. 

Then, the actions are abstracted from the formatters.  Basically the fact an error occured is SEPARATE from how that error's message will express itself.  So, you might have a string "Please enter a valid Social Security Number" but that can be presented as an Alert Box, a  DHTML layer, a tiny gif with an ALT tag tooltip, a colored textbox, or a flashing graphic (or whatever you want).  Separating activities from presentation from storage... it's "3 tiered" design within a replacement validation framework.  It's so crazy it just might work. :) 

It's generated JavaScript supports IE, IE/MAC, Netscape 6+, Mozilla and Opera.  It also supports isomorphic SERVER-SIDE validation, so if your use bypasses your client-side code, you'll catch them on the server side.  Pretty sweet.

Localization (So few people care...but everyone should)

There's a LOT (most?) of ASP.NET controls out there that just assume that everyone in the world speaks English (or cares to).  I've picked up a few Calendar controls from random places that literally crashed when told to display a different culture.

We have banks live in such out of the way places as Greece, Thailand, and Malaysia.  We need our systems and ASP.NET controls to be fully "culture smart." (PLUG: Come see my Internationalizing ASP.NET Sites at VSLive!)  The VAM validation controls support using ResourceID strings for complete localization of Error Messages.  This culture awareness is throughout the framework, and it's appreciated as I work on banks en español.

JavaScript you DON'T have to write (and ought not be writing)

One cool extra is a concept called a FieldStateController.  From the site:

"The FieldStateController controls can monitor edits and clicks on any type of field on the page. They can use the same Conditions used by validators to determine if a certain condition is met before taking their action. For example, the checkbox must be checked, the textbox must contain some text, or the listbox must have a selection."

You can use any attribute supported in the DOM or in DHTML so changes in the state of one or more fields can change the attributes in an other objects on the page.  This translates to less custom JavaScript that I have to write.

Extensibility

There's a great (and incredibly long) Developer's Guide that explains how you can extend the framework.  For example, I wanted to support entering dates like this "YYYYMMDD" as well as the standard culture-specific "MM/DD/YYYY".   So, I derived from the existing PeterBlum.DateTypeConverter my own CustomScottDateTypeConverter.  It's one class that handles both server and client side validation/conversion.  I added code to handle my new "DataType" and delegated the rest to the base class.  No need to reinvent the wheel.

Freebees

There's also a bunch of freebee features that aren't neccessarily validation related, but are useful to your application. 

  • There's a "TrueBrowser" object model that lets you sniff browser capabilities more easily than the standard BrowserCaps stuff. 
  • There's a FilteredTextBox to limit keystrokes to just decimals, currency or integers.
  • LocalizedLabels - smart string lookup labels for multi-lingual sites.I know

Documentation (When it's good, OH it's good.)

His documentation is obscene.  Like, it's embarassing.  No single developer should write this much documentation.  You'd think there's a separate documentation department.  Probably he's locked his mom in the garage and got her making PDFs.  I mean that in the best way.  Except, he's put me in a bad spot...if I ever start my own company, I need to have doc at least this good...and I'm not sure I want the bar set that high.

Support

We had to call support with a CRAZY threading bug in our 1.02 version of the VAM that happened if two people with the identical browser hit the site within a few milliseconds of each other if that browser has never hit the site before and the site is under exteme load.  (This happened twice in a week, so you get the idea that it's was obscure and not a big deal.)  Anyway, I explained it to Peter and he had already found and fixed it for the next minor version! 

Conclusion

He's got two pricing levels of VAM, and Level 2 (the one that includes all the good stuff) is only $100 and even the Redist or Source Code License is reasonable.  That's insane.  Anyway, check it out.  It's SO rich and SO powerful that it may freak you out as it's overwhelming. Seriously, take a day and spend time with it.  Read the instructions, and read them again. 

The real value for me is that we are using it's extensibility points to extend it WELL beyond it's standard features and firmly into the Financial Vertical I work in.  We've extended and added to the point where it's now the Corillian Validation Framework, and that's just great for us...our job isn't to write validation code, it's to make powerful banking sites.  And that suits me just fine.  Microsoft should buy this guy and integrated the whole thing into ASP.NET 2.x.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.