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

D

D. Shane Fowlkes

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
*********************************
 
D

D. Shane Fowlkes

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
*********************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top