By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,286 Members | 2,443 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,286 IT Pros & Developers. It's quick & easy.

Background color on web button

P: n/a
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
Nov 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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]
- mv*@spam.guard.caspershouse.com

"Rik Brooks" <rb*****@hhcc.com.donotspam> wrote in message
news:14**********************************@microsof t.com...
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

Nov 17 '05 #2

P: n/a
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

Nov 17 '05 #3

P: n/a
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 [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"Rik Brooks" <rb*****@hhcc.com.donotspam> wrote in message
news:14**********************************@microsof t.com...
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


Nov 17 '05 #4

P: n/a
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]
- mv*@spam.guard.caspershouse.com

"Rik Brooks" <rb*****@hhcc.com.donotspam> wrote in message
news:8A**********************************@microsof t.com...
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 [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"Rik Brooks" <rb*****@hhcc.com.donotspam> wrote in message
news:14**********************************@microsof t.com...
>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
>
>


Nov 17 '05 #5

P: n/a
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 [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:Oj**************@tk2msftngp13.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Rik Brooks" <rb*****@hhcc.com.donotspam> wrote in message
news:8A**********************************@microsof t.com...
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 [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"Rik Brooks" <rb*****@hhcc.com.donotspam> wrote in message
news:14**********************************@microsof t.com...
>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
>
>


Nov 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.