0

I'm working on an ASP.NET application. Text is taken from a database where line breaks are stored as '\r\n' and I'm putting the text into a TextBox with MultiLine enabled. However, I can't seem to get a line break into the TextBox

string description = description.Replace("\\r\\n", "<br/>");
lblDescriptionV.Text = description;

I've tried replacing the line break with: <br/> , &#13;&#10;, &#10; but the value is just printed into the texbox. So it'll read: "Line 1<br/>line 2".

Santosh Panda
  • 7,235
  • 8
  • 43
  • 56
user1662292
  • 137
  • 1
  • 2
  • 12

2 Answers2

4

Replace it with Environment.NewLine

Prasanth V J
  • 1,126
  • 14
  • 32
1
<asp:TextBox runat="server" ID="txtArea" TextMode="MultiLine" Rows="10" />

code behind:

protected void Page_Load(object sender, EventArgs e)
{
    txtArea.Text = "Hello\nThere\nFriend";
}

Therefore you require the following:

string description = "Hello\\r\\nThere\\r\\nFriend";
description = description.Replace("\\r\\n", "\n");

Note: You cannot enter breaks into a label (lblDescriptionV)

TriCron
  • 141
  • 2
  • 11
  • Thanks. A bit odd how everywhere I looked said replace '\n' with this and that. But it works now :) PS. lblDescriptionV is actually a textarea - a little mistake with my naming convention there... – user1662292 Oct 21 '14 at 12:44