Auto resize textarea or Asp.net multiline textbox based on content using javascript

  ASP.NET Projects

Complete ASPX Code:-

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

 <html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <style type="text/css">
        .clsTxt {
            width: 200px;
            min-height: 25px;
            max-height: 200px;
            resize: none;
        }
    </style>
    <script>
        function resizeTextBox(txt) {
            txt.style.height = "1px";
            txt.style.height = (1 + txt.scrollHeight) + "px";
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <table>
                <tr>
                    <td>Description: </td>
                    <td>                       
                        <asp:TextBox ID="txtDescription" CssClass="clsTxt" runat="server" onkeyup="resizeTextBox(this)" TextMode="MultiLine"></asp:TextBox>
                    </td>
                </tr> 
            </table> 
        </div>
    </form>
</body>
</html>

 

43 thoughts on - Auto resize textarea or Asp.net multiline textbox based on content using javascript

LEAVE A COMMENT