tags:

views:

218

answers:

4

Hi,

I have an asp Label control used for displaying error messages to the user. My client would like certain words in these messages to be underlined. How would this be accomplished?

Thank you, James

A: 

I total misunderstood the question blah.

Embed the HTML into the label's text property.

Nathan Taylor
I can't underline the whole string of text, only certain words are to be underlined.
James
+1  A: 

Though a bit hacky, you can assign HTML markup to the Label's Text property. Something like this should suffice:

Label.Text = "this is an <span class='underlineIt'>underlined expression</span>";

The would assign class underlineIt to the words "underlined expression." Within the underlineIt CSS class, you can set the rule text-decoration: underline.

David Andres
This sounds like it could work, I will give it a try. Thank you
James
A: 

The contents of a literal control are not html encoded so you could swap out the label control then insert tags around the words you want underlined.

<asp:Literal ID="lblTitle" runat="server" Text='my <u>underlined</u> text' />
Tim Santeford
I would use <span class='underlineIt'>underlined expression</span> to wrap the words as did David Andres. I think however that asp might html encode the labels text by default not giving you what you want.
Tim Santeford
Tim, This works fine.... Thanks!
James
A: 

Simpler version of David Andres's solution :

Label.Text = "this is an <u>underlined expression</u>";
Canavar
Thanks, I like it!
James
Actually, this is the one I used... Easy! Thanks
James