Displaying Formatted Text

by | 11 Feb 2017

Dynamically displaying formatted text is a pain. A label control can’t keep the format. People suggest to use multiline texbox but that doesn’t look good in a web page for announcement. Some suggests to use RichTextBox but that requires a great deal of coding. I always look for a simple solution, so I created a HtmlGenericControl (pre) on the fly and added it to a panel control. Hola, the format was protected. You can even add html control to a label too; I tested and it worked. Afterwards, you can use necessary style in the pre tag for your need.

//need to use the following library/namespace
Using System.Web.UI.HtmlControls;

//code behind
HtmlGenericControl hgcPre = new HtmlGenericControl(“pre”);
hgcPre.InnerText = “your formatted text”; //in my case data comes from a table
pnlFormatted.Controls.Add(hgcPre);

//style
Pre
{
  font-family: Tahoma, Verdana, Helvetica, Sans-Serif;
}

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

Other Posts

In Loving Memory of Michael Brown: A Neighbor’s Unforgettable Smile

I was shocked to hear that our neighbor, Michael Brown, passed away on May 2, 2024, and even more so to find out only after thirty days had passed. I had gone to see him because I noticed his house was up for sale. I assumed he was moving to Florida or somewhere else...

Color of Validation Text

You may have noticed that the color of the validation text is black in framework 4.0. To make it red again I found the following solution but some users say that it doesn’t work always. <?xml version="1.0"?> <configuration> <system.web>...

Social media

I have some friends who don’t like Facebook or twitter (may be they even hate it). I told them to join several times but they avoided by giving many excuses. I think social media makes communication easier. I only have their phone numbers but sometimes I don’t want to...

মাততে পারেনি

যদিও শব্দটার অর্থ জানাছিল তবুও সিলেটী ভাইয়েরা যখন নিজেদের ভাষায় কথা বলেন তখন দুর্বোধ্য শোনায়। তাই যখন আমি আমার ছেলেকে আরবি পড়ার শেষে মসজিদ থেকে আনার সময় অন্য একজন অবিভাবক জিজ্ঞেস করলেন 'মাততে পারেনি' আমি বুঝতে পারিনি। দ্বিতীয়বার যখন বললেন 'ছেলে বাংলায় মাততে পারেনি'।...

Silent Treatment

We have a comedian at our workplace. One day, during the beginning of my carrier in this place, I asked him if I could check my e-mail from my work computer. He responded, “Go crazy, just keep the pants on”. I didn’t laugh, so he said it again. I just smiled and went...

Verizon Sucks

After having it for more than three years I had to cancel my Verizon Internet (FIOS) service on 09 September 2017. When I was cancelling I mentioned that bill close date was 06 September, so can I be excused for the last two days but she said no and I would be paying...

Chatting

Yesterday, I was waiting in line to get this year’s flu shot at my work. Two women ahead in the line were loudly expressing their personal opinions about other people they knew, what movies and movie stars they liked etc. It was quite annoying. Afterward many others...