This example demonstrates on how are we going to set the Height of the MultiLine TextBox automatically when the the contents of the TextBox is larger than the size of the TextBox.
First thing you need is DON'T set the Height of the TextBox in the mark up (ASPX) and do the following:
C#
protected void TextBox1_Load(object sender, EventArgs e)
{
int charRows = 0;
string tbCOntent;
int chars = 0;
tbCOntent = TextBox1.Text;
TextBox1.Columns = 10;
chars = tbCOntent.Length;
charRows = chars / TextBox1.Columns;
int remaining = chars - charRows * TextBox1.Columns;
if (remaining == 0)
{
TextBox1.Rows = charRows;
TextBox1.TextMode = TextBoxMode.MultiLine;
}
else
{
TextBox1.Rows = charRows + 1;
TextBox1.TextMode = TextBoxMode.MultiLine;
}
}
VB.NET
Protected Sub TextBox1_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim charRows As Integer = 0
Dim tbCOntent As String
Dim chars As Integer = 0
tbCOntent = TextBox1.Text
TextBox1.Columns = 10
chars = tbCOntent.Length
charRows = chars / TextBox1.Columns
Dim remaining As Integer = chars - charRows * TextBox1.Columns
If remaining = 0 Then
TextBox1.Rows = charRows
TextBox1.TextMode = TextBoxMode.MultiLine
Else
TextBox1.Rows = charRows + 1
TextBox1.TextMode = TextBoxMode.MultiLine
End If
End Sub