Click here to Skip to main content
Licence CPOL
First Posted 31 Oct 2006
Views 32,441
Downloads 88
Bookmarked 23 times

Length Validation for all Multiline Textboxes on a Page

By | 30 Dec 2007 | Article
How to enable length validation for all Multiline textboxes on a page using a line of code...

Sample Image - MultilineLengthValidator.jpg

Introduction

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.

Enjoy...

License

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

Member

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.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralInvalid Character when run the EncloseScriptBlock PinmemberMember 19015009:46 28 Apr '11  
GeneralExcellent - Small update PinmemberMember 14188847:59 31 Mar '09  
GeneralGood Job! Pinmemberedusabrz12:31 23 Feb '09  
GeneralVB.net version of this code Pinmemberdolphinpointe12:04 10 Sep '08  
GeneralRe: VB.net version of this code [modified] Pinmemberdolphinpointe13:48 10 Sep '08  
GeneralThanks PinmemberSam.M17:59 22 Jan '07  
GeneralError Pinmembermishenkovks21:30 8 Nov '06  
AnswerRe: Solved PinmemberSina Falahati8:29 9 Nov '06  
GeneralThank you Pinmembermishenkovks3:32 8 Nov '06  
Generalnice job PinmemberMajid Shahabfar1:29 7 Nov '06  
GeneralRe: nice job PinmemberSina Falahati8:30 9 Nov '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web01 | 2.5.120528.1 | Last Updated 30 Dec 2007
Article Copyright 2006 by Sina Falahati
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid