html page:
=======
<script type="text/javascript">
function textCounter(field,maxlimit)
{
if (field.value.length > maxlimit)
{
return false;
}
}
</script>
Page Load Events:
=============
protected void Page_Load(object sender, EventArgs e)
{
txtmaxlen.Attributes.Add("onkeydown", "return textCounter(this, 5)");
txtmaxlen.Attributes.Add("onkeyup", "return textCounter(this, 5)");
txtmaxlen.Attributes.Add("onmousedown","return textCounter(this, 5)");
txtmaxlen.Attributes.Add("onmouseup","return textCounter(this, 5)");
txtmaxlen.Attributes.Add("onblur", "return textCounter(this, 5)");
}
script type="text/javascript"
ReplyDeletefunction textCounter(field, maxlimit) {
if (field.value.length maxlimit)
field.value = field.value.substring(0, maxlimit); // maxLength);
{
return true;
}
}
/script