473,387 Members | 1,573 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,387 software developers and data experts.

Formatting a label control - still learning.....

I'm trying to use some basic logic (in a goof off test page) so when a
form's data is evaluted, the color of a label **might** be red. The error I
keep getting is:

Compiler Error Message: BC30311: Value of type 'String' cannot be converted
to 'System.Drawing.Color'.
Line 15: MyMessage.Forecolor = "#FF0000"

Would someone mind looking at and suggesting a fix for my code. I'm having
a hard time getting a working example to learn from and experiment with....

Thanks!
<% @Page Explicit="True" Language="VB" Debug="True" %>
<%@ Import NameSpace = "System.Drawing.Color" %>

<html>
<script runat="server">
Sub OKButton_Click(Sender As Object, E As EventArgs)
Dim UserAge As Integer
Dim DogAge As Integer

UserAge = MyAge.Text
DogAge = UserAge / 7

If UserAge > 200 Then
MyMessage.Text="If you were a dog, you'd be " & DogAge & " years old
and you're too old."
MyMessage.Forecolor = "#FF0000"
Else
MyMessage.Text="If you were a dog, you'd be " & DogAge & " years old."
End If

End Sub
</script>

<body>
<h1>If You Were A Dog</h1>
<form runat="server">
How old are you?<br />
<asp:textbox id="MyAge" runat="server" />
<asp:button text="OK" onclick="OKButton_Click" runat="server"/><br>
<asp:label id="MyMessage" runat="server" />
</form>
</body>
</html>
--
*********************************
D. Shane Fowlkes - TMM
Saving the world, one web site at a time.
http://www.shanefowlkes.com
*********************************

Nov 18 '05 #1
1 1205
I did get it to work bu changing the color assignment to this:

MyMessage.Forecolor = Drawing.Color.Red
but is there a way I can apply this method using hexidecimal values instead
of alias or RGB? I'd rather use "#FF0000" istead of "red" or
"RGB(255,0,0)".
--
*********************************
D. Shane Fowlkes - TMM
Saving the world, one web site at a time.
http://www.shanefowlkes.com
*********************************
"D. Shane Fowlkes" <sh***@raccoonbob.com> wrote in message
news:uy**************@TK2MSFTNGP10.phx.gbl...
I'm trying to use some basic logic (in a goof off test page) so when a
form's data is evaluted, the color of a label **might** be red. The error I keep getting is:

Compiler Error Message: BC30311: Value of type 'String' cannot be converted to 'System.Drawing.Color'.
Line 15: MyMessage.Forecolor = "#FF0000"

Would someone mind looking at and suggesting a fix for my code. I'm having a hard time getting a working example to learn from and experiment with....
Thanks!
<% @Page Explicit="True" Language="VB" Debug="True" %>
<%@ Import NameSpace = "System.Drawing.Color" %>

<html>
<script runat="server">
Sub OKButton_Click(Sender As Object, E As EventArgs)
Dim UserAge As Integer
Dim DogAge As Integer

UserAge = MyAge.Text
DogAge = UserAge / 7

If UserAge > 200 Then
MyMessage.Text="If you were a dog, you'd be " & DogAge & " years old
and you're too old."
MyMessage.Forecolor = "#FF0000"
Else
MyMessage.Text="If you were a dog, you'd be " & DogAge & " years old." End If

End Sub
</script>

<body>
<h1>If You Were A Dog</h1>
<form runat="server">
How old are you?<br />
<asp:textbox id="MyAge" runat="server" />
<asp:button text="OK" onclick="OKButton_Click" runat="server"/><br>
<asp:label id="MyMessage" runat="server" />
</form>
</body>
</html>
--
*********************************
D. Shane Fowlkes - TMM
Saving the world, one web site at a time.
http://www.shanefowlkes.com
*********************************

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: BBFrost | last post by:
I'm receiving decimal values from database queries and placing them on a report page. The users want to see the following .... Db Value Display Value 123.3400 123.34...
3
by: Mervin Williams | last post by:
Can the text property be set inside the html using the String.Format() method? If not, is there some other means of setting the format for a label statically (not in code)? Thanks in advance, ...
31
by: jcrouse | last post by:
Is there a quick and easy way to change the color of a label controls border from the default black to white? Thank you, John
6
by: jcrouse | last post by:
I am rotating some text is some label controls. In the one place I use it it works fine. In the other place I use it I can't figure out the syntax. I don't really understand the event. Where it...
1
by: Alex Maghen | last post by:
I'm taking text from a multi-line TextBox into a database. Then, on other pages, I'm displaying that text as read-only. But the problem is, when I set the Text property of a Label control to that...
1
by: AmitKu | last post by:
I've got the Gridview going at full speed, and I've enabled editing, but when I click on the "edit" button, this ugly editing UI comes up. Well it's not ugly, but it's not great either. How do I...
5
by: Carla | last post by:
I have Access 2000. I made a mailing list database and for the life of me can't remember how to format the zip code field so it will print on the label as xxxxx-xxxx. I have tried various - 9, #,...
10
by: Lyn | last post by:
Hi, I would like to make a bound text box not visible if it is empty (not just disable it). This option is not available from the standard conditional formatting feature (at least, not that I can...
1
by: dbuchanan | last post by:
I want to fill a textbox or a label or with lines from a listbox. I want to preserve the lline for line as it comes from the list box. I do not want the test to run-on. I suppose it is okay to wrap...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.