Displaying Multi line wrapped text in web form

Hi,


Many a times there is requirements for us to display text in multi-line in web pages. The first try that most of the people do is by giving a fixed width to the label. But this never works.

Height and Width works only for block level element. Label is an inline element and hence setting width does not work.

 

What you can instead do is use a textbox with CSS that will make it looks like a label. To do this we need to set the following properties.

Wrap = true;
rows = 5 (change this number as per your need.)
ReadOnly = true
TextMode = multiline (you need this to have multiple lines)
BorderStyle = None
BorderWidth = 0

Also when setting the text property, you should replace all the <Br> tags to new Line characters.

TextBox1.Text.Replace(Environment.NewLine, "<br>");

Vikram


Share this post   Email it

Feedback

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Enter the text you see in the box:
 

Copyright © 2006 - 2010 Vikram Lakhotia