Background color on web button

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using a plain web forms button on an asp page - Is there any way to
programatically change it to a custom color?
 
Rik,

Have you checked the style attribute for the button? You should be able
to set the backcolor style for the button to change the color of it.

Hope this helps.
 
Hey Rik,

Do you want your button color to change dynamically based on a user
action or do you just wish that your button color is something other
than the drab windows gray?

Regarding the later (just changing the color) I recommend using a css
style that defines a buttons color. Below is an example css style that
would make all buttons on your page black with lime green text:

BUTTON{
/*Set text color of button to lime*/
color: Lime;
/*Set backround color of button to black*/
background-color: Black;
}

If you need help with css i recommend this link:
http://www.w3schools.com/css/default.asp
Also, a GREAT css editor is TopStyle lite and can be found here:
http://www.bradsoft.com/download/index.asp

If you want to have text look like a button but not be an actual button
widget, check out the following link (allows a tags to look like
buttons):
http://4guysfromrolla.com/webtech/100601-1.shtml

In truth, i think your best bet is css styling of a button. If you want
the color of that button to change dynamically, just use javascript to
respond to an event which in turns accesses a specific button by id and
changes its class/id value.

Hope that helps

-pete
 
I tried

btn_active.Attributes["BackColor"] = "#C1E180";

but that gave me an error.

--
----------------------------------------
Magic is not in the hands of the magician but in the mind of the audience.

Animadverto est verus




Nicholas Paldino said:
Rik,

Have you checked the style attribute for the button? You should be able
to set the backcolor style for the button to change the color of it.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Rik Brooks said:
I am using a plain web forms button on an asp page - Is there any way to
programatically change it to a custom color?
--
 
Rik,

You have to set the style attribute to something like this:

bnt_active.Attributes["style"] = "background:#050505";

This causes the button to be rendered in HTML as:

<input type="button" style="background:#050505">


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Rik Brooks said:
I tried

btn_active.Attributes["BackColor"] = "#C1E180";

but that gave me an error.

--
----------------------------------------
Magic is not in the hands of the magician but in the mind of the audience.

Animadverto est verus




Nicholas Paldino said:
Rik,

Have you checked the style attribute for the button? You should be
able
to set the backcolor style for the button to change the color of it.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Rik Brooks said:
I am using a plain web forms button on an asp page - Is there any way to
programatically change it to a custom color?
--
----------------------------------------
Magic is not in the hands of the magician but in the mind of the
audience.

Animadverto est verus
 
you can also use style sheets

1. define a style sheet
in style.css

btnbgcolor

{

font-family : Verdana, Arial, Helvetica, sans-serif;

font-size : 10px;

text-align : left;

color : #ffffff;

font-weight: bold;

background-color:#25486E;

width: 100px;

text-decoration: none;

}

2. include style sheet in your page
i usually have the path to css etc defined in web.config file as a key
then do
Page.Controls.Add(new
LiteralControl(ConfigurationSettings.AppSettings["csspath"]));
3. give your button attribute of class
btn.attributes.add("class","btnbgcolor");


Now you can use stylesheets. :) you can use the same methods for
tablecells, rows, etc etc.
You know the benefits of CSS :)

hth

Nicholas Paldino said:
Rik,

You have to set the style attribute to something like this:

bnt_active.Attributes["style"] = "background:#050505";

This causes the button to be rendered in HTML as:

<input type="button" style="background:#050505">


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Rik Brooks said:
I tried

btn_active.Attributes["BackColor"] = "#C1E180";

but that gave me an error.

--
----------------------------------------
Magic is not in the hands of the magician but in the mind of the
audience.

Animadverto est verus




Nicholas Paldino said:
Rik,

Have you checked the style attribute for the button? You should be
able
to set the backcolor style for the button to change the color of it.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I am using a plain web forms button on an asp page - Is there any way
to
programatically change it to a custom color?
--
----------------------------------------
Magic is not in the hands of the magician but in the mind of the
audience.

Animadverto est verus
 
Back
Top