• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 474
  • Last Modified:

Multiline TextBox expand as characters exceed space

I want to put a 2 line multiline textbox on the page.

As the user fills up the two lines, I want it to grow another line, etc.; so they still see the entire box as they're typing.
Maybe also have the ability for a maxrows of so much.

Is there anyway to do this?

Using VB and asp.net 3.5 sp1.

Starr Duskk
Starr Duskk
1 Solution
You should do this in javascript.

This code might come in handy for me too :)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <script type="text/javascript" language="javascript">
function Resize(obj) {
  var txt = obj.value;
  var maxRows = 10;
  var maxChar = 100;
  var arrTxt = txt.split(/[\n\f\r]/);
  var cntLines = arrTxt.length;
  for (var i = 0; i < arrTxt.length ; i ++ )
    if (Math.ceil(arrTxt[i].length / 20) > 1) {
      cntLines += Math.ceil(arrTxt[i].length / 20) - 1;
  document.getElementById("Text1").value = arrTxt.length + " breaks ; " + cntLines + " lines";
  if (obj.rows > maxRows) {
    alert('Max Rows Reached!');
    return false;
  if (txt.length > maxChar) {
    alert('Max Characters Reached!');
    obj.value = obj.value.substr(0, maxChar)
    return false;
  if (obj.rows == maxRows) return true;
  obj.rows = cntLines + 1;
  return true;
    <textarea id="TextArea1" cols="20" rows="2" onkeyup="return Resize(this)"></textarea>
    <input id="Text1" type="text" />

Open in new window

Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
excellent! Thanks!

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now