کد های جاوا اسکریپت مورد نیاز :
<script>
function textCounter(field,maxlimit) {
var cntfield='mydiv';
if (document.getElementById(field).value.length > maxlimit)
document.getElementById(field).value = document.getElementById(field).value.substring(0, maxlimit);
else
document.getElementById(cntfield).value = maxlimit - document.getElementById(field).value.length ;
}
</script>
کد های html مورد نیاز :
<strong><span style="color: #9acd32"> پیام:</span></strong>
<table border="1" style="border-right: #cdd6e6 1px solid; border-top: #cdd6e6 1px solid;
border-left: #cdd6e6 1px solid; border-bottom: #cdd6e6 1px solid" dir="ltr">
<tr>
<td style="width: 100px">
<textarea id="msgBody" runat="server" class="msgbodyinput" dir="ltr" name="msgBody" style="font-weight: bold; width: 300px; color: #000066; border-right: 0px solid;
border-top: 0px solid; border-left: 0px solid; border-bottom: 0px solid; height: 58px;" ></textarea></td>
</tr>
<tr>
<td dir="rtl" style="width: 100px">
<table>
<tr>
<td style="height: 12px; hight: auto;">
<asp:Label ID="Label2" runat="server" Text="تعدار کاراکتر های مجاز:" Width="116px"></asp:Label></td>
<td style="width: 60px; height: 12px">
<input id="mydiv" style="border-right: #ffffff 0px solid; border-top: #ffffff 0px solid;
border-left: #ffffff 0px solid; width: 60px; border-bottom: #ffffff 0px solid; color: black;"
type="text" /></td>
</tr>
</table>
</td>
</tr>
</table>
کد های سرور ساید مورد نیاز :
msgBody.Attributes.Add("onkeydown", "textCounter('" + msgBody.ClientID + "',78)");
TextBox1.Visible = true;
موفق باشید