asp.nethtmlgenericcontrol

ASP.NET: Bold parts of text using HtmlGenericControl


I am a complete ASP.NET newbie, so this will probably be simple.

I have a label which text is set dynamically in the code behind using the following pseudo code

label.Text = string.Format(SOME-DYNAMIC-MESSAGE(ID,1), name, day);

The SOME-DYNAMIC-MESSAGE has a form of, where {0} and {1} refers to variables name and day.

Hello {0}, today is {1}.

I need to make those variables bold. I am trying to wrap them in span, so I can access them from CSS using this code

HtmlGenericControl bold = new HtmlGenericControl("span");
    bold.InnerText = name;
    bold.Attributes.Add("class", "bold");

label.Text = string.Format(SOME-DYNAMIC-MESSAGE(ID,1), bold, day);

but it doesn't work, no extra wrapper added. It even stopped to show me the the content of the variable.

Anybody knows how to fix this?


Solution

  • Try :

    label.Text = string.Format(SOME-DYNAMIC-MESSAGE(ID,1), "<span style=\"font-weight:bold\">" + bold + "</span>", "<span style=\"font-weight:bold\">" + day + "</span>");