user3284717
user3284717

Reputation: 35

How do I use a string variable to set an html control color

I am trying to set the colors of my controls on my webpage to be variables. For example I would store a value of "#000000" in a database and when the page loads it would put that value in the original html tag. So <asp:Button ID="btnTesta" runat="server" Text="Button" ForeColor='<% MYVALUE%>' />.

Upvotes: 0

Views: 996

Answers (2)

Learning
Learning

Reputation: 20041

This should change your button background color or ForeColor color

yourButtonName.BackColor = Color.Red;
yourButtonName.ForeColor = Color.Black;

You need to include System.Drawing namespace as Color class belongs to that. Like this

using System.Drawing;

And ofcourse you need to add the reference to System.Drawing DLL in your project to use this namespace and Color class.

enter image description here

Refrence Button background colour

Upvotes: 0

Mairaj Ahmad
Mairaj Ahmad

Reputation: 14624

You can assign value from code behind.

btnTesta.ForeColor = System.Drawing.ColorTranslator.FromHtml("yourvaluefromdatabase");

Upvotes: 1

Related Questions