Single line textboxes render as an HTML <input> tag - which supports a max
length.
The Multiline Textbox, renders as an HTML <TextArea> which doesn't support a
length property.
So, one workaround is to roll your own by calling a JavaScript function that
checks the length of the text entered. The function gets called on every
keypress and denies further data entry when the max length is reached. Of
course the JavaScript function needs to ignore some keys. This one should
work. It limits to 300 characters:
This is how your multiline text box will render.
<textarea name="MyTextArea" rows="3" id="MyTextArea" onkeypress="return
checkMaxLength(event,this)" TAMaxLength="300"
style="width:350px;"></textarea>
Here's your JavaScript function:
function checkMaxLength(e,el) {
switch(e.keyCode) {
case 37: // left
return true;
case 38: // up
return true;
case 39: // right
return true;
case 40: // down
return true;
case 8: // backspace
return true;
case 46: // delete
return true;
case 27: // escape
el.value='';
return true;
}
return (el.value.length<el.getAttribute("TAMaxLength"));
}
-HTH
"Nathan Sokalski" <> wrote in message
news:...
> When using a MultiLine TextBox (which generates a TextArea) setting the
> MaxLength property has no effect. However, because I am saving the
> contents of the TextBox to a DB field, I must limit the number characters
> allowed. I would prefer not to do this serverside because that would
> require a large amount of trips between the server and client (especially
> for a 200 character limit). Is there a way to do this? Thanks.
> --
> Nathan Sokalski
>
> http://www.nathansokalski.com/
>