Chaging the forecolor for just a part of a label (Asp.Net)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • firebirds98
    New Member
    • Feb 2008
    • 15

    #1

    Chaging the forecolor for just a part of a label (Asp.Net)

    I am using .Net and I want to make a specific part of a label a different text color then the label it self.

    Ex.

    Code: ( text )
    lblresults.Text = "We found " + objquote.Count. ToString + " results."


    The labels forecolor is Blue but I want the part "objquote.Count .Tostring" part to be red.

    I dont want to use multiple labels.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Originally posted by firebirds98
    I am using .Net and I want to make a specific part of a label a different text color then the label it self.

    Ex.

    Code: ( text )
    lblresults.Text = "We found " + objquote.Count. ToString + " results."


    The labels forecolor is Blue but I want the part "objquote.Count .Tostring" part to be red.

    I dont want to use multiple labels.

    You need to use different labels to show different coloured text.

    Labels are rendered as <span> tags. These tags are issued a CSS that controls the colour of the text within the <span> tags. Therefore, you need to use different labels to highlight text.

    You could add your own <span> tags within the String that you are creating. Just be aware that some applications are set up to render any html tags found in text as harmless (eg the < is sent to the browser as &lt and the > is sent to the browser as &gt)

    EG:
    Code:
    lblresults.Text = "We found <span style="""+"color:#C00000;'""+">" + objquote.Count.ToString + "</span> results."
    -Frinny

    Comment

    • firebirds98
      New Member
      • Feb 2008
      • 15

      #3
      Had to switch some your quotation marks around but you are awesome.

      Thanks for the Code.

      Here is what works:

      Code:
      lblresults.Text = "We found <span style=" + "'color:#C00000;'" + " > " + objquote.Count.ToString + " </span> results."

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        The <font> tag could have worked to.

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          Originally posted by Plater
          The <font> tag could have worked to.
          I think the <font> tag is considered obsolete...

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            Originally posted by Frinavale
            I think the <font> tag is considered obsolete...
            First the <center> tag now the <font> tag? They're out to get me!

            Comment

            • Frinavale
              Recognized Expert Expert
              • Oct 2006
              • 9749

              #7
              Originally posted by Plater
              First the <center> tag now the <font> tag? They're out to get me!
              I know the feeling :(

              Comment

              • Curtis Rutland
                Recognized Expert Specialist
                • Apr 2008
                • 3264

                #8
                I felt that way about <table>s.

                Comment

                Working...