Set Color to Elements in my control

A

Angel

I am trying to set HTML elements in my server control to the ForeColor setting for the control. For example I create a server control which I inherit from WebControls. WebControls exposes the ForeColor property of the control. Now in my code I render certain tags in which I want to set its Style attribute "color" to what the developer selected in the ForeColor of the control.

writer.writeBeginTag("DIV")
writer.writeAttribute("ID", "TEST")
writer.writeAttribute("STYLE", "COLOR: " & Me.ForeColor.ToString & ";")

The Me.ForeColor is the Control ForeColor setting. Unfotunately when I test this piece of code and I view the source it does writes the TAG this way when I view the source for the HTML.

<DIV ID="TEST" STYLE="COLOR: color white">

HTML does not recognize this coding so it does not set the color. I tried setting this setting in my code:

writer.writeBeginTag("DIV")
writer.writeAttribute("ID", "TEST")
writer.writeAttribute("STYLE", "COLOR: " & Me.ForeColor.ToArgb & ";")

And it wrote this in the HTML Source:

<DIV ID="TEST" STYLE="COLOR: -1">

HTML Did not recognize this either. So How can I convert the color in the property of the control to something that will be written correctly when the HTML is built? Is there a Hex function that can call on the ForeColor property to return the Hex value and then write it to the HTMLWriter stream?

thanks...
 
T

Teemu Keiski

Hi,

see System.Drawing.ColorTranslator class. It can convert a Color to HTML
representation and back (as well as to other presentation formats)

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke

Angel said:
I am trying to set HTML elements in my server control to the ForeColor
setting for the control. For example I create a server control which I
inherit from WebControls. WebControls exposes the ForeColor property of the
control. Now in my code I render certain tags in which I want to set its
Style attribute "color" to what the developer selected in the ForeColor of
the control.
writer.writeBeginTag("DIV")
writer.writeAttribute("ID", "TEST")
writer.writeAttribute("STYLE", "COLOR: " & Me.ForeColor.ToString & ";")

The Me.ForeColor is the Control ForeColor setting. Unfotunately when I
test this piece of code and I view the source it does writes the TAG this
way when I view the source for the HTML.
<DIV ID="TEST" STYLE="COLOR: color white">

HTML does not recognize this coding so it does not set the color. I tried
setting this setting in my code:
writer.writeBeginTag("DIV")
writer.writeAttribute("ID", "TEST")
writer.writeAttribute("STYLE", "COLOR: " & Me.ForeColor.ToArgb & ";")

And it wrote this in the HTML Source:

<DIV ID="TEST" STYLE="COLOR: -1">

HTML Did not recognize this either. So How can I convert the color in the
property of the control to something that will be written correctly when the
HTML is built? Is there a Hex function that can call on the ForeColor
property to return the Hex value and then write it to the HTMLWriter stream?
 

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,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top