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

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

আইনজীবি

আমি এক সময় আইনজীবি হতে চেয়েছিলাম, কিন্তু খেয়াল করে দেখেছি কোন কিছুতে যুক্তি দিতে গেলে তৎক্ষণাৎ তেমন কিছু মনে পড়ে না। যুক্তিগুলো আমার অনেক পরে বা পরের দিন মাথায় আসে। ভাগ্যিস আইনজীবি হইনি। না খেয়ে মরার সম্ভাবনা...

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

AT&T Cheated Me

I complained many times against AT&T, still stayed with them because they gave me good prices for phones. This time they lied to me and I believe I won’t stay with them after my contract is over unless they give me what they promised. First, they sold me Samsung...

Voted

Last Tuesday was Election Day. There was not enough publicity about the candidates, so I didn't know anyone or their agenda. You wouldn't believe; I voted for the names that sounded better. The vote started at 7:00AM and I voted at 5:00PM. Yet, I was the 25th voter....

Library Time

I try to take the kids to a library once in a week to spend some times with the books and bring some books home, so they can read them during the next week. Hopefully, they will build a habit of going to the library on their own. May be one or both the kids will be...

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