A New Internet Library: Add Your Website/Blog or Suggest A Website/Blog to our Free Web Directory http://anil.myfunda.net.

Its very simple, free and SEO Friendly.
Submit Now....

Thursday, January 8, 2009

Updates to the TextBox Word / Character Counter Control

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 >



Source Click Here.

No comments:

Post a Comment

Post your comments here:

Originals Enjoy