Question

I have a text that have som \n in it. But when showing the text in a div there are no line feeds.

How do I make a line feed in a div???

I have tried to Replace("\n","&lt;br /&gt;") and Replace("\n","&lt;p&gt;&lt;/p&gt;"). But the <br /> is showed instead of a line feed.

ASP.NET:

<div class="text"> <%: newsItem.Text %></div>

CSS:

.text
{
  color: Black;
  margin-top: 10px;
  margin-bottom: 10px;      
}
Was it helpful?

Solution

Use:

<%= newsItem.Text %>

Instead of:

<%: newsItem.Text %>

The second method implicitly HTML encodes the string.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top