HTML in label

5 posts, 0 answers
  1. Danny
    Danny avatar
    29 posts
    Member since:
    Feb 2012

    Posted 24 Apr 2012 Link to this post

    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
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 27 Apr 2012 Link to this post

    Hello Danny,


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


    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Danny
    Danny avatar
    29 posts
    Member since:
    Feb 2012

    Posted 09 May 2012 Link to this post

    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


  5. Danny
    Danny avatar
    29 posts
    Member since:
    Feb 2012

    Posted 04 Jul 2012 Link to this post

    Could anyone please help me with this, or give me a definitive answer if this is possible or not?

    Thanks,
    Danny
  6. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 04 Jul 2012 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017