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

Visiting Parks

During this summer I started to take my kids to different parks, so they can spend some time outside of the house and get some physical movements rather than playing video games the whole day. I take pictures every time we go outside. Also, I make videos of less than...

Graduation Party

On Saturday 02 July 2022, we celebrated important milestones of our children. We had four graduates this year in our family - one graduated from kindergarten, two from elementary schools, and the oldest one among them from middle school. Kids were free to spend as...

Power of Social Media

There is no doubt social media is very powerful - Turkish President was able to thwart a coup by posting his video message in twitter. Recently, I was able to use it for my benefit too. I fought with Whirlpool's supervisor (over the phone) to fix my microwave oven but...

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...

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...

Money Well Spent

I bought two dahlia plants with 2/3 small flowers last summer from Walmart. After planting them in my front yard I was pleasantly surprised to see so many beautiful flowers during summer and fall. However, I didn’t know that they had bulbs underneath the plants, so...

Surprise!

I know a lady who first fled her country to another country for a better life and then staged a marriage with an American citizen to come and stay in the USA. She described it as a “business deal”. According to her that marriage was never consummated. Later she became...