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

Realization

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

USPS Stinks

United States Postal Service won’t try to deliver your parcel if you miss it the first time even though postmen come to deliver mails six days in a week. Instead they will leave a pink slip which says you can pick it up after a certain date. First of all, postmen...

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

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

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

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

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