Wrapping Text Line in a label control

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

 

4 Comments

Comments have been disabled for this content.