Updates to the TextBox Word / Character Counter Control

Posted by: 4GuysFromRolla.com Headlines, on 07 Jan 2009 | View original | Bookmarked: 0 time(s)

When storing user-supplied text data into a database, it is essential that the length of the user's input does not exceed the size of the corresponding database table field. To ensure that a user's input is within the legal bounds, you can: set the TextBox control's MaxLength property (although this does not work for multi-line textboxes); use a validation control, such as my TextBoxLengthValidator control or a RegularExpressionValidator; use server-side code to check the Length property of the string before storing it in the database; or some combination of the above. The problem with these solutions is that they are not very interactive. The user doesn't know how close she is to hitting the maximum number of characters.

In October 2007 I created a custom ASP.NET server control that uses JavaScript to interactively display the number of characters and/or words a user has typed into a textbox, and wrote about it in an article titled Creating a TextBox Word / Character Counter Control. In the TextBoxCounter control's initial implementation is simply reported how many words or characters the user had entered. Because this control is most useful in scenarios where there is a limit to the number of characters or words allowed, a natural enhancement would be to allow the page developer to specify a maximum number of characters or words allowed. With this information, the control could be updated to show how many characters or words remain. Moreover, the appearance of the TextBoxCounter could be modified based on how close the user was to reaching the word or character limit.

Recently, 4Guys reader David Dude implemented these future enhancements and shared his code changes with me; I've since integrated them into the code base. This article looks at the enhancements to the TextBoxCounter control class and demonstrates how to use them in an ASP.NET page. Read on to learn more!
Read More >

Advertisement
Free Agile Project Management Tool from Telerik
TeamPulse Community Edition helps your team effectively capture requirements, manage project plans, assign and track work, and most importantly, be continually connected with each other.
Category: ASP.NET | Other Posts: View all posts by this blogger | Report as irrelevant | View bloggers stats | Views: 1531 | Hits: 44

Similar Posts

  • Behaviors vs Subclassing in Silverlight more
  • CodeDigest.Com Article,Codes,FAQs - April,2009 more
  • ASP.NET MVC Controls and Good versus Evil more
  • ASP.NET Data Control Events more
  • Handling Formats Based On Url Extension more
  • WPF Presence Controls for Office Communicator 2007 more
  • Announcing a new Control from August Wind Software more
  • Delegating Decorators more
  • Silverlight 2 Beta 1 Controls Available, including Source and Unit Tests more
  • NavigationWindow, WinFormsHost and TextBoxes: backspace bug more

News Categories

.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Data | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD