You have to wire functions for the events
onpaste, onkeyup and onfocus of the area for which you want to do this action.
For an asp textbox I think you have to consider only OnTextChanged event.
For textarea
<INPUT id="counterMessage" readOnly size="3" value="250" name="counterMessage">
<TEXTAREA onpaste="PasteCounter(this.form.txtAreaMessage,this.form.counterMessage,250);"
id="txtAreaMessage" onkeyup="textCounter(this.form.txtAreaMessage,this.form.counterMessage,250);"
style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; OVERFLOW: hidden; BORDER-LEFT: 0px; WIDTH: 99%; BORDER-BOTTOM: 0px; HEIGHT: 95px; TEXT-ALIGN: justify"
onfocus="textCounter(this.form.txtAreaMessage,this.form.counterMessage,250);" name="txtAreaMessage"
rows="3" runat="server"></TEXTAREA>
function PasteCounter(field, countfield, maxlimit)
{
var len;
var txt = clipboardData.getData("Text");
txt = field.value + txt
len = parseInt(txt.length);
if ( len > maxlimit )
{
event.returnValue=false;
txt = txt.substring(0, maxlimit);
field.value = txt;
alert("Only " + maxlimit + " characters are allowed");
}
countfield.value = maxlimit - txt.length;
}
function textCounter(field, countfield, maxlimit)
{
if (field.value.length > maxlimit )
{
field.value = field.value.substring(0, maxlimit );
alert("Only " + maxlimit + " characters are allowed");
}
countfield.value = maxlimit - field.value.length;
}
The countfield textbox is for showing remaining characters.