MaxLength property doesn’t work for multi-line text box and text area in ASP.Net. Using the JavaScript code given below, we can easily set the max length for multi-line text box or text area.

function restrict(obj,size)
var key = window.event.keyCode;
key==8 //backspace
|| key==46 //delete
|| key==37 //left
|| key==38 //up
|| key==39 //right
|| key==40 //down
window.event.returnValue = false;
function trim(obj,size)
obj.value = obj.value.substring(0,size);
<form name=”frm”>
<textarea id=”txt” onkeydown=”restrict(this,10);” onchange=”trim(this,10);”></textarea>

Leave a Reply

%d bloggers like this: