Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5950663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:25:33+00:00 2026-05-22T17:25:33+00:00

I have some user input that I am outputting to a label. I have

  • 0

I have some user input that I am outputting to a label.

I have used HTML.Encode in order to show the input in the way the user entered it (ignoring as a html tag).

However, I have noticed that the user input like New Line are not using in the label. It’s simply displayed as white space.

I’ve done this

                msg.Text = msg.Text.Replace(Environment.NewLine, "<br />");

which seems to now be displaying the right input.

Is that the best way to do this? Or is there like a common method that can convert newLines, tabs, etc. all of the invisible formatting things into HTML tags?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:25:33+00:00Added an answer on May 22, 2026 at 5:25 pm

    I don’t know of any other way. What I usually do (in case you have a single “\n” or a “\r\n” combo) is replace all “\r\n” first, then any single “\n” last.

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

    For tabs you can use 4 non-breaking spaces.:

    lbl.Text = lbl.Text.Replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;")
    

    To preserve any spacing (as html will aggregate multiple continuous spaces into a single space) use:

    lbl.Text = lbl.Text.Replace("  ", "&nbsp;&nbsp;")//Replace every 2-space pair.
    

    Remember to Encode your text first before adding in markup like <br /> that you intentionally want to render.

    You could also use a TextBox, set it’s MultiLine property to “true” and Enabled to “false” if you want to display the information with the original carriage returns without resorting to inserting markup. I think the label is the best choice though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web page that prompts for user input via DropDownLists in some
So I have a form that accepts some input from a user that may
I have some user input. Within my code, I ensure that the following symbols
I have written a user control that captures some user input and has a
So I have some code here that takes user input from a standard web
I have a script that updates a CSS file based upon some user input
I need to validate some user input that is encoded in UTF-8. Many have
I have a program that calculates some user input, and I would like to
Say I want to have a simple web app that takes some user input,
I have an Excel-based application that gathers some user input, and makes some calculations

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.