Fire Hand
Fire Hand

Reputation: 26396

Change the color of disabled link button

I have a link button in my grid view and it will be disabled when it meets certain condition. My question is, when the button is disabled, the color of the button will change to gray and i dun wan it to be gray, perhaps black. I have tried using the following code the change gray color to others but it's not working, You guys have any idea to do do this?

Have tried on:

LinkButton.ForeColor = Drawing.Color.Black
or
LinkButton.CssClass = "BlackLnkBtn"
or
LinkBUtton.Attributes("class") = "BlackLnkBtn"

Upvotes: 2

Views: 20800

Answers (6)

Randy
Randy

Reputation: 11

Himadri's solution is the correct one. The reason why it may not work for some is that your code may have set the css before setting the .enabled. The order is important here because setting the .enabled actually changes the class.

Upvotes: 1

Fire Hand
Fire Hand

Reputation: 26396

i have figured out a solution, where, instead of disabling the button, i will just set it OnClick attributes to false when under certain condition and using CSS Style to remove the underline of the text.

This is my code...

<CSS>

<style type="text/css">
    .BlackLnkBtn
    {
        color:black;
        text-decoration:none;
        cursor:default;
    }
</style>

<Code Behind>

LinkButton1.Attributes.Add("class", "BlackLnkBtn")
LinkButton1.Attributes("onclick") = "return false;"

Upvotes: 1

Himadri
Himadri

Reputation: 8876

Try the css and code below:

css:

<style type="text/css">
    .disabledbtn
    {
    background-color:#000000;
    color:#FFFFFF;
    }
</style>

Code:

LinkButton1.Enabled = False
LinkButton1.CssClass = "disabledbtn"

Upvotes: 3

rick schott
rick schott

Reputation: 21137

You can only change the text color in FireFox, maybe others, IE won't budge.

<style type="text/css">
    .BlackLnkBtn
    {
        color: Red;
    }
</style>

Upvotes: 0

Daniel
Daniel

Reputation: 2948

Try LinkBUtton.Attributes.Add("class", "yourclass");

Upvotes: 0

Ryu
Ryu

Reputation: 8749

Try adding the following CSS to <head>

<style type="text/css">
.BlackLnkBtn
{
background-color:black;
/* or */
color:black;
}
</style>

This will set the background-color:black property on the button after you set the class to BlackLnkBtn.

Upvotes: 0

Related Questions