Geeks With Blogs

News

Microsoft MVP


DZone MVB


Moderator at CodeASP.NET


Quiz Master







free counters
Free counters
Added on January 19,2012


Follow Me @vmsdurano

A bit About Me



Disclaimer
The opinions expressed herein are my own personal opinions and does not represent the opinions of my employers. Nor does it represent the opinion of my dog, because I don’t have one.


Vinz' Blog (ProudMonkey) "Code, Beer and Music ~ my way of being a programmer"

This example shows how we are going to set the Height of the MultiLine TextBox automatically when 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 then 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

 

That's it!

Technorati Tags: ,
Posted on Tuesday, February 17, 2009 4:50 PM ASP.NET , Tips&Tricks | Back to top


Comments on this post: Automatically Adjust the Hieght of the TextBox based on its Contents

# re: Automatically Adjust the Hieght of the TextBox based on its Contents
Requesting Gravatar...
Its works man...Thanks.....
Only I just modifed TextBox1.Columns = 70 because of space....
Thanks
Left by Apil on Apr 26, 2012 7:41 PM

comments powered by Disqus

Copyright © Vincent Maverick Durano | Powered by: GeeksWithBlogs.net