Note that there are some explanatory texts on larger screens.

plurals
  1. POReplace(Environment.NewLine, "<br/>") is not working as expected when displaying text on a web page
    primarykey
    data
    text
    <p>I'm not sure why the following code is not working as intended:</p> <pre><code>litMessage.Text = messageBody.Replace(Environment.NewLine, "&lt;br/&gt;") </code></pre> <p>Where <code>litMessage</code> is the name of the literal control and <code>messageBody</code> is the name of the string variable.</p> <p>My intention is to output a string onto a web page and to replace the line breaks with a br tag so that it can be displayed on the page correctly. However, nothing is replaced. When viewing the page source, it looks like the line breaks still exist in the string. Similarly, when displaying the string via MsgBox, it displays normally as well. I have also tried wrapping the output with the <code>pre</code> tag and it displays the line breaks properly as well.</p> <p>The string was originally entered by a user through the use of an asp:Textbox and saved into a MSSQL database. It's retrieved and displayed on another webpage using an asp:Literal control. The only thing that happens to the string before it is submitted is that it is trimmed (i.e. <code>textbox.Text.Trim())</code>.</p> <p>Perhaps there is something I did not consider?</p> <p><strong>Edit #1:</strong> Due to time constraints, I've decided to just wrap the text with the <code>pre</code> tag. It's an acceptable work around as it preserves the line breaks. Unfortunately, it doesn't explain why the code didn't work in the first place. In the meantime, I'll just leave the question unanswered until I find a proper answer.</p> <p><strong>Edit #2:</strong> Solution found and answered below. UpdatePanel tag added to the question for future reference.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload