This example demonstrates how to print or display the contents of the MultiLine TextBox in a Label Control and retain its line breaks.

Basically MultiLine Mode of TextBox uses Environment.NewLine to create a new line. So if you try to display the values of TextBox in  a Label Control or print it on the page and retain its position then you can replace the  Environment.NewLine with <BR> Tag since Label control doesn't recognized Environment.NewLine.

Here's a sample demo  below for your reference:

ASPX

<asp:TextBox ID="TextBox1" runat="server" Height="300px" Width="300px"
                           TextMode="MultiLine"/>

<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" 
                         Text="Print to Label Control"/>
<br />
<asp:Label ID="Label1" runat="server" Text="Label" Height="300px" 
                       Width="300px"/>

RELEVANT CODES

 
protected void Button1_Click(object sender, EventArgs e){        
     Label1.Text = TextBox1.Text.Replace(Environment.NewLine, "<BR/>");
}
 
and here's the page output below

Technorati Tags: ,