My Wife's First Contribution to 4Guys
Like yours truly, my wife also creates ASP.NET applications for a living. I shudder to think what our future children will be like, perhaps they'll be bilingual from an early age, speaking both English and C#. A common question on many newsgroups and online forums is how to use the validation controls in ASP.NET 1.x to limit the user's input to a specified number of characters. The typical answers are, “Use the TextBox's MaxLength property,” or, “Use a CustomValidator.” I was never a big fan of either of these approaches - the former still requires server-side code since a nefarious user could easily cirumvent this setting in their browser; the latter approach is better, but not very portable to other pages or Web sites, as the server-side and (optional) client-side code must be repeated on each page/site that utilizes the CustomValidator.
So, I've always wanted to write a custom validation control that provided this functionality. It's been on my TODO list for a while, but has very low priority. Anywho, my ol' lady had a slow day at work a week ago or so, and decided to whip up this control that's been on my plate for a while. She's not a fan of writing like yours truly, so I whipped up an article describing her code and illustrating how to use the control - you can learn more at Creating a TextBoxLengthValidator Validation Control. There's a live demo available here. You can download the complete source code, along with a compiled assembly, here.
Enjoy!