Friday 1 February 2013

MaxLength in Multiline Textbox ASP.NET

MaxLength in Multiline Textbox ASP.NET

Well Yesterday I came across this question.. So I want to share the solution with all the Community Members. Special Thanks to VINZ for providing the nice solution:

<html xmlns="" >
<head runat="server">
    <title>MultiLine TextBox MaxLength</title>
        <script type="text/javascript" language="javascript">

        function ValidateLimit(obj, maxchar) {
            if ( obj = this;
            var remaningChar = maxchar - obj.value.length;
            var lb = document.getElementById('<%= Label1.ClientID %>');
            lb.innerHTML = remaningChar;

            if (remaningChar <= 0) {
                obj.value = obj.value.substring(maxchar, 0);
                lb.innerHTML = "0";

    <form id="form1" runat="server">
        <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" onkeyup="ValidateLimit(this,140)">   </asp:TextBox> <br />
    Remaining char: <asp:Label ID="Label1" runat="server" Text="140"></asp:Label>


Apart from this here are few other alternatives:

Using Javascript

Using Jquery

1 comment:

  1. I read this article, nice conversation about text.keep sharing more.


Thank You for Your Comments. We will get back to you soon.

back to top