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

Identity Theft

I guess finally my name is added to the list of 41 million Americans who are victims of stolen identities. Someone opened credit card twice in Kohl's (https://www.kohls.com/) using my credentials. First time, I was able to cancel the card before it was used but second...

Gabriel García Márquez

“One Hundred Years of Solitude” by Gabriel García Márquez was one of the novels that we had to read in our undergraduate “classical literature” class (13 years ago). We read this as a class and discussed it. At the beginning, all the Spanish names in the book were...

Eid Mubarak

Eid-ul-Ajha is a two-and-a-half-day celebration. Today is the first day and this morning, we went to pray at our local Northeast Philadelphia Islamic Center. We attended the first jamat at 8:00am. The main Eid prayer took place in the front yard of the mosque, but we...

Testicular Cancer

Recently, I took a agency mandated class on communication. It was a good class and the lessons learned there can be used for effective communication in work or in personal life. The instructor shared some experiences involving his client, parents, and siblings. He...

Obnoxious Driver

Around noon on Saturday 13 July 2019 I was driving towards Queens, NYC on Brooklyn Queens Expressway (BQE) and little before exit 23 (still in Brooklyn) I was trying to go to the right lane but a car came too fast and too close to mine in the right lane, so I went...

Realization

It dawned on me – If there was no love there would be nothing…

Neighborhood Nuisance

It was about 9:30pm on Saturday 17 December 2022, someone knocked our door hard – first I thought it was an Amazon delivery guy but didn’t see anyone or nothing was left on our doorstep. We checked the footage from our security camera and saw someone was running away...