Change the color of a button with a disabled link

I have a link button in my grid view and it will be disabled when certain conditions are met. My question is that when the button is disabled, the color of the button will change to gray, and I will not be gray, possibly black. I tried using the following code to change the gray to others, but it doesn't work. Do you guys want to do this?

Have tried:

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

      

+2


source to share


6 answers


I developed a solution where instead of disabling the button, I simply set the OnClick attributes to false when under certain conditions and using CSS Style it will 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;"

      

+1


source


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"

      

+3


source


Himadri's decision is correct. The reason this might not work for some is because your code may have set the css before setting the .enabled. Order is important here because setting .enabled does indeed change the class.

+1


source


Try adding the following CSS to <head>

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

      

This will set the property background-color:black

to the button after you set the class to BlackLnkBtn.

0


source


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

0


source


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

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

      

0


source







All Articles