473,320 Members | 2,097 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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.
Sep 19 '08 #1
7 2947
Frinavale
9,735 Expert Mod 8TB
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:
Expand|Select|Wrap|Line Numbers
  1. lblresults.Text = "We found <span style="""+"color:#C00000;'""+">" + objquote.Count.ToString + "</span> results."
-Frinny
Sep 19 '08 #2
Had to switch some your quotation marks around but you are awesome.

Thanks for the Code.

Here is what works:

Expand|Select|Wrap|Line Numbers
  1. lblresults.Text = "We found <span style=" + "'color:#C00000;'" + " > " + objquote.Count.ToString + " </span> results."
Sep 19 '08 #3
Plater
7,872 Expert 4TB
The <font> tag could have worked to.
Sep 19 '08 #4
Frinavale
9,735 Expert Mod 8TB
The <font> tag could have worked to.
I think the <font> tag is considered obsolete...
Sep 19 '08 #5
Plater
7,872 Expert 4TB
I think the <font> tag is considered obsolete...
First the <center> tag now the <font> tag? They're out to get me!
Sep 22 '08 #6
Frinavale
9,735 Expert Mod 8TB
First the <center> tag now the <font> tag? They're out to get me!
I know the feeling :(
Sep 22 '08 #7
Curtis Rutland
3,256 Expert 2GB
I felt that way about <table>s.
Sep 22 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jurgen Oerlemans | last post by:
Hello, I want to change to forecolor of a label. The label is named "lblDevice1" I create a variable called Var Dim Var Var = "lblDevice1" So the next step is: Var.ForeColor =...
1
by: Eric Robishaw | last post by:
I'm adding items to a CheckBoxList Control, and need the text in each checkbox list item to be a specific color. Here's what I'm trying: ListItem li = new ListItem(GroupName, GroupID);...
4
by: rkbnair | last post by:
I have an image placed on an aspx page. <img id="xyz" onMouseOver="abc()" src="c:\temp\ijk.jpg"> My Text to Display How can I change the forecolor of the text 'My Text to display' in function...
2
by: Mike P | last post by:
Is it possible to change the forecolor of a Span programmatically? Cheers, Mike *** Sent via Developersdex http://www.developersdex.com ***
3
by: ApexData | last post by:
I am using labels in the form header to sort the fields of a continuous form. When the user clicks on a label, the fore color becomes blue. When the user clicks on a different Label, I would like...
3
by: =?Utf-8?B?TWFyaw==?= | last post by:
I have an ASP.Net 1.1 site that uses Server.Transfer() heavily. Specifically, I use a page called /misc/pagenotfound.aspx to implement logic that maps URLs of the format /vdir/california to a...
0
by: jobs | last post by:
This code works at setting my login failure message, but does not set the color for some reason. Protected Overrides Sub OnLoad(ByVal e As EventArgs) If IsPostBack Then If Login.FailureText <""...
3
by: crjunk | last post by:
Hi Everyone, I have a web form that I would like to enhance. What I'd like to do is this: A user adds/edits the text in a textbox. I want the adjoining label to change color. Example: User...
3
by: premprakashbhati | last post by:
hi, good evening.. i am going to upload an image in a web form .....for that iam using HTML input(file) control and one web control button i.e., Upload_Button() here is the code ...its work fine...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.