Geek Articles

Categories

 

Subscribe

Daily Updates Subscribe geekarticles update via email Subscribe geekarticles update via RSS

 
GeekArticles Database SQL Server

Creating a TextBox Word / Character Counter Control

Author: aspnet.4guysfromrolla.com | Published: 31st Oct 2007 | Visited: 146 times | Add Comment
Filed in: SQL Server

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. For example, imagine that you have defined a table with a field named Comments of type varchar(50). In a web page, the user is presented with a textbox into which to enter their comments. After doing so and clicking the "Save" button on the page, a postback ensues and the database is updated with the user's input. If the user entered more than 50 characters worth of comments, however, running the database UPDATE statement will result in an exception with the message: String or binary data would be truncated. To prevent these types of exceptions, you need to ensure that the user's input does not exceed the size defined in the database. If it does, you must cancel the update and somehow alert the user that their input is too verbose. One way to proactively alert users that their input is too long is to interactively show them how many characters they've entered, along with how many maximum characters are allowed. This can be accomplished with a bit of client-side JavaScript code that runs whenever the user presses a key within the textboxes whose lengths you want to track and display. In this article we'll look at a custom ASP.NET 2.0 server control I built named TextBoxCounter that uses JavaScript to display the total number of words and/or characters entered into a specified TextBox. The control's complete source code is available at the end of the article and you're welcome to use this control anyway you like (free of charge, of course). Read on to learn more! Read More >

Read Article
 

Sponsored Links

 


Related Articles

 Creating a scoreboard in Spry in five easy steps Build a real-time scoreboard with notifications for your personal webs ...

 Check maxlength of multiline textbox in javascript This post will help you to resolve problem of checking maxlength of Multilie tex ...

 Self Validating TextBox A self populating and self validating textbox control with business object aware ...

 Article :: Creating and Destroying Java Objects Java expert Josh Bloch discusses the ins and outs of creating and destroying obje ...

 Selling Your Gadget: Chapter 4 Creating Vista Gadgets using HTML, CSS & JavaScript This chapter discuss the Sidebar Gadget revenue mo ...

 .NET Building Blocks: Custom User Control Fundamentals Find out the gritty details required to create, test, use, inherit, install, and distribute .NET User Controls of all ty ...

 Multiple File Upload User Control This article describes how to create an user control with event & propert ...

 Tile Editor Control A control to edit maps or small pictures in tile f ...

 Quick! Word Association: XML Today I took some time to quickly scan through a backlog in my feed reader. There were a good number anti-XML articles cropping up. This got me thinking. What do you think of when I say "XML"? I personally associat ...

 Creating a Proxy to Download PDF Reports from SRS How to create a proxy that downloads PDF reports from SRS and then stream them back to the client bro ...



Next: Building Interactive User Interfaces with Microsoft ASP.NET AJAX: Using the UpdatePanel



Post Comment

Name:


Email:
 (Optional. Used for Notification)

Title:

 
Comment:


Validation Code:
 <=>  (Enter this code in text box)





Latest Articles

 

Popular Articles

Sponsored Links