Click here to Skip to main content
14,177,621 members
Click here to Skip to main content
Add your own
alternative version


23 bookmarked
Posted 31 Oct 2006
Licenced CPOL

Length Validation for all Multiline Textboxes on a Page

, 30 Dec 2007
Rate this:
Please Sign up or sign in to vote.
How to enable length validation for all Multiline textboxes on a page using a line of code...

Sample Image - MultilineLengthValidator.jpg


It is commonly known that the MaxLength attribute does not work for textboxes with the TextMode property set to MultiLine since they are rendered as <textarea> HTML controls, which miss this property.

There are lots of great articles around to solve this, but using custom controls etc., is too time expensive for larger projects.

This approach iterates through all the controls in a page (or other container controls) and attaches a JavaScript to all multiline textboxes to enable length validation. It works with AJAX / ATLAS, FormViews, and all commonly known browsers.

How to use

Add multiline textboxes to your page by setting the MaxLength property. Now, all you have to do is use one line of code...

For performing length validation on all multiline textboxes on a page:

Put TextAreaValidator.CheckMaxLength(this); inside the page's Page_Load function.

For performing length validation on a specific textbox:

Put TextAreaValidator.CheckMaxLength(theTextBox); inside the page's Page_Load function.

For FormViews (also inside ATLAS UpdatePanels), use the FormView's OnItemCreated event with:

TextAreaValidator.CheckAllMaxLengthsWithinParentControl((FormView)sender), since the container controls are created at runtime and previously inaccessible.



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Sina Falahati
Austria Austria
Sina Falahati is a Medical student at Vienna Medical University and also student at Technical University of Vienna.

His preferred languages are Music, C++, C#, Turbo Pascal / Delphi, XML, German and Persian.

You may also be interested in...

Comments and Discussions

GeneralInvalid Character when run the EncloseScriptBlock Pin
Member 190150028-Apr-11 9:46
memberMember 190150028-Apr-11 9:46 
GeneralExcellent - Small update Pin
0x29A31-Mar-09 7:59
member0x29A31-Mar-09 7:59 
GeneralGood Job! Pin
edusabrz23-Feb-09 12:31
memberedusabrz23-Feb-09 12:31 version of this code Pin
dolphinpointe10-Sep-08 12:04
memberdolphinpointe10-Sep-08 12:04 
GeneralRe: version of this code [modified] Pin
dolphinpointe10-Sep-08 13:48
memberdolphinpointe10-Sep-08 13:48 
GeneralRe: version of this code (Working) Pin
DidiKunz7-Aug-12 6:22
memberDidiKunz7-Aug-12 6:22 
GeneralThanks Pin
Sam.M22-Jan-07 17:59
memberSam.M22-Jan-07 17:59 
GeneralError Pin
mishenkovks8-Nov-06 21:30
membermishenkovks8-Nov-06 21:30 
AnswerRe: Solved Pin
Sina Falahati9-Nov-06 8:29
memberSina Falahati9-Nov-06 8:29 
GeneralThank you Pin
mishenkovks8-Nov-06 3:32
membermishenkovks8-Nov-06 3:32 
Generalnice job Pin
Majid Shahabfar7-Nov-06 1:29
memberMajid Shahabfar7-Nov-06 1:29 
GeneralRe: nice job Pin
Sina Falahati9-Nov-06 8:30
memberSina Falahati9-Nov-06 8:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04 | 2.8.190526.1 | Last Updated 30 Dec 2007
Article Copyright 2006 by Sina Falahati
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid