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

Singularity

The statistician I. J. Good wrote “Intelligence Explosion” where he suggested that if a machine is created to be more intelligent than humans, it will be able to create a better machine. This process recursively creates an increasingly intelligent machine, which leads...

National Pride vs. People’s Lives

More lives could have been saved but the Bangladeshi government reportedly refused to take assistance from some friendly countries in rescuing garment workers from collapsed “Rana Plaza” because of national pride. I am not sure where is the pride coming from. Other...

মাততে পারেনি

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

No Visa Required

All of a sudden my wife decided to visit her parents in Bangladesh. She would take our little one with her. This is his first visit to Bangladesh, so his passport needs Bangladeshi visa. Fortunately, Bangladesh government provides “No Visa Required” (NVR) stamp on the...

The Curious Case of Children’s Motrin Costs

I recently needed to purchase Children’s Motrin, which I had bought from Walmart a few days ago for $7.68. However, since Walmart is a bit far from my location, I decided to compare prices online at Rite Aid and CVS. To my surprise, Rite Aid listed it for $8.79, while...

Kurbani

This was the first year when I went to butcher shops for Kurbani of Eid-ul-Azha (Annual religious sacrifice). We deposited $500 to a butcher shop in Pipersville, PA to get a bull of around 1800lbs. That was a Thursday and he told our organizer that he only had big...

My worst experience with doctors

It was December 2015, my second son was playing with colored cotton balls and I thought I saw him putting one small cotton ball in one of his nostrils (he was 1 year+ at that time). We saw something red in his nose but we weren’t 100% sure because the inside of a nose...