0

I have a formatted text stored in a database column as listed below. This formatting is preserved when an email is sent using SSIS. However when I display it using a a web page, the formatting is not preserved – it comes in single line.

What is the best way to display it in HTML by preserving format?

Note: We need to achieve this without any third party control. But we can use standard ASP.Net controls

UPDATE Report_Type SET report_template_txt = 

'Updates:   
-----------------
        Transactions Received for 10 


Adjustments :  
---------------------------


Adjustment holds 

        Holds past 1 month – 5'

HTML Source and Rendering:

enter image description here

REFERENCE:

  1. save html-formatted text to database

  2. database text with html formatting, how to pull it into my asp.net page

  3. .NET: How to display string as a formatted HTML?

  4. HTML Decoding within textarea

3
  • 1
    Your references are looking at the problem the wrong way round. You have NON HTML formatted text, which when rendered to a webpage are displaying as a single line, hence you need to convert TO HTML. The references you have linked to are showing you how to take HTML formatted text already in the database, and present it in a textbox / plain text email etc... Commented Nov 6, 2012 at 15:22
  • @RemarkLima Can't we render it properly using any encoding techniques? Commented Nov 6, 2012 at 15:33
  • 1
    no, as HTML isn't an encoding per se, it's unicode / ascii encoded plain text with the relevant markup to allow it to render. Another way to look at it, if you want to convert data to XML, how do you do this without an XML schema to output towards? The HTML markup is the schema in this instance. I'd be very happy to be corrected on this! Commented Nov 6, 2012 at 15:49

1 Answer 1

0

You'll need to replace line breaks with <br /> tags:

string _outputText; // = Some query to get the string
_outputText = _outputText.replace(Environment.NewLine, "<br />");

// Output - Assign the string to whereever, or however suits now it's HTML friendly
Response.Write(_outputText); // Or asssign to literal etc...
lblSomeLabel.text = _outputText;

You may also wish to replace spaces with non-breaking spaces, like so:

_outputText = _outputText.Replace(" ", "&nbsp;");

Then you may also wish to use a fixed width font such as courier, or courier-new so that the formatting is consistent.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.