challengeAccepted
challengeAccepted

Reputation: 7590

How to make string bold in code behind

Is there a way to make a string bolder in code behind using C# .NET?

I tried:

string TypeofDay = "<span style='font-weight: bold'>Type Of Day</span> ";
txtbox.Text = TypeofDay + ": " + "Delivery Day"

I am concatenating TypeofDay(bold) and "Delivery Day" to display in a textbox.

Upvotes: 2

Views: 47480

Answers (6)

Slai
Slai

Reputation: 22866

A bit hacky alternative can be to use Unicode bold characters
http://qaz.wtf/u/convert.cgi?text=Type+Of+Day

txtbox.Text = "𝗧𝘆𝗽𝗲 𝗢𝗳 𝗗𝗮𝘆: 𝖣𝖾𝗅𝗂𝗏𝖾𝗋𝗒 𝖣𝖺𝗒"

Upvotes: 1

Lukas
Lukas

Reputation: 2923

TextBox, no, however you could use a label.

myLabel.text = "<b>bold text</b> normal text <u>underlined text</u> <span style='font-size:Large; color:Red'>Big red text</span>";

Upvotes: 1

Danny G
Danny G

Reputation: 3779

You could layer a div on top of the textbox. Since the text formatting would change anyway once the user started typing, you can just hide the div once focus is given to the div, thus showing the text box. If nothing is entered and focus is lost, show the div again.

Upvotes: 0

Maciej
Maciej

Reputation: 7961

You can't make text bolder by enclosing text value in tags. You must change attribute of a control that displays that text for example by setting its CSS class or changing code-behind property:

txbSendMessageBody.Font.Bold = true;

Upvotes: 3

demoncodemonkey
demoncodemonkey

Reputation: 11957

You can't make some bits bold and some bits not bold, in an <asp:TextBox>.

Upvotes: 3

user743382
user743382

Reputation:

PS. I am concatenating few bold strings and some other strings to display in a textbox.

A HTML text box does not support this. ASP.NET (usually) generates HTML; if HTML does not support this, you cannot solve it from the server side.

Upvotes: 2

Related Questions