This is a migrated thread and some comments may be shown as answers.

HTML in label

4 Answers 156 Views
Input
This is a migrated thread and some comments may be shown as answers.
Danny
Top achievements
Rank 1
Danny asked on 24 Apr 2012, 01:17 PM
Hi,

I've run in to a problem that I can't seem to find a solution for. We want to set the label for a RadTextBox with HTML code, like this

Name <span class='required'>*</span>

We use this to give the required star a different color / style, we set it like this from the code behind:
txtT.Label = Required ? string.Format("{0} <span class='required'>*</span>", value) : value;

However the problem is the the html code is not rendered as HTML, but as readable text showing us this label in the browser.
So it shows us: Name <span class='required'>*</span>
Instead of: Name *

How can I solve this and make the label write the HTML as I set it?

Thanks,
Danny

4 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 27 Apr 2012, 09:37 AM
Hello Danny,


<asp:Literal ID="a1" runat="server" Text=" <b> jay </b> esh"></asp:Literal>


Thanks,
Jayesh Goyani
0
Danny
Top achievements
Rank 1
answered on 09 May 2012, 03:49 PM
Hi Jayesh,

Thanks for you reply, but how does a Literal solve this problem?
I can't place a literal in the RadTextBox label, that would be nesting a asp control in a string property.

Regards,
Danny


0
Danny
Top achievements
Rank 1
answered on 04 Jul 2012, 02:43 PM
Could anyone please help me with this, or give me a definitive answer if this is possible or not?

Thanks,
Danny
0
Princy
Top achievements
Rank 2
answered on 05 Jul 2012, 04:52 AM
Hi Danny,

One suggestion is that you can add a different class to the last element using Jquery as follows.

ASPX:
<telerik:RadTextBox ID="RadTextBox1" runat="server" LabelCssClass="LabelClass" Label="Name*"  >
</telerik:RadTextBox>

JS:
$('.LabelClass').each(function ()
  {
     var $this = $(this);
     var sin = $this.html();
     if (sin.length < 1) return;
     var sout = sin.substring(0, sin.length - 1) + '<span class=required>' + sin.charAt(sin.length - 1) + '</span>';
     $this.html(sout);
  });

Thanks,
Princy.
Tags
Input
Asked by
Danny
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Danny
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or