ASP.Net MaxLength & Character Count for SpellTextAreas
Understanding MaxLength
In ASP.Net the MaxLength property does not normally affect Multiline TextBoxes.
With ASPNetSpell - the MaxLength property can be applied to enforce a maximum length of input at the clieny side
E.g.
SourceCode:<ASPNetSpell:SpellTextBox ID="SpellTextBox1" runat="server" MaxLength="200">..</ASPNetSpell:SpellTextBox>
Adding a Character Count
Almost any conventional "Character Count" script can also be applied. We have provided one in the demo below for your convenience.
Full ASPX Source Code with Character Count
SourceCode:<%@ Register Assembly="ASPNetSpell" Namespace="ASPNetSpell" TagPrefix="ASPNetSpell" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Max Length Demo for ASP-Net-Spell</title>
</head>
<body>
<form id="form1" runat="server">
<ASPNetSpell:SpellTextBox ID="SpellTextBox1" runat="server" MaxLength="200">
...
</ASPNetSpell:SpellTextBox>
<div id='MyCharCount1'></div>
<script type='text/javascript'>
setInterval(function(){CharacterCount('<%=SpellTextBox1.ClientID%>','MyCharCount1')},45);
function CharacterCount(TextArea,FieldToCount){
var myField = document.getElementById(TextArea);
var myLabel = document.getElementById(FieldToCount);
if(!myField || !myLabel){return false}; // catches errors
var MaxChars = myField.maxLengh;
if(!MaxChars){MaxChars = myField.getAttribute('maxlength') ; }; if(!MaxChars){return false};
var remainingChars = MaxChars - myField.value.length
myLabel.innerHTML = remainingChars+" Characters Remaining of Maximum "+MaxChars
}
</script>
</form>
</body>
</html>
