I have a label containing some text and I want to highlight or change the color of some words in the text of the label and not all of the words. It has to be dynamic. Any suggestions?
It’s for c# with ASP.NET in a user control in webpart in sharepoint
On the server-side, you could just embed some Html in your Label’s text (VB):
That’s the basic mechanism, but ‘dynamic’ could mean a lot of things here. If you post some more details about exactly what you’re doing, I might be able to help more.
One more thought: as Rob Allen pointed out, the Literal control may be a slightly better choice in this situation since it’s intended to emit raw Html, whereas the Label wraps the text in a span so that the whole thing can be formatted easily.
Check this out for more details: StackOverflow: Literals versus Labels
For the record, depending on the situation I think a Label may actually be okay here.