Add Line Breaks to a Label Control
Problem
You want to insert line breaks in the text of a Web control such as the Label control.
Solution
Add HTML markup to the string. For example, you can use <p> to denote paragraphs or <br> to divide a line.
Discussion
You can’t use the carriage return character (or the System.Environment.Newline constant) to insert a line break in the text of a Web control. Instead, you must use HTML tags. For example, the following code snippet creates three lines of text:
lblMessage.Text = "This is line one.<br>" lblMessage.Text &= "This is line two.<br>" lblMessage.Text &= "This is line three."
Figure 15-4 shows the use of multiple lines in a Web control.
Figure 15-4. Multiple lines in a label.
Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.