开发者

Style disabled ASP.NET Linkbutton with background image

I am using a simple ASP.NET linkbutton control.

<asp:LinkButton ID="LinkButtonDelete" runat="server" CssClass="linkButtonDelete">Delete</asp:LinkButton>

I am styling this button with the following css definitions:

.linkButtonDelete:link
{
    background: transparent url(/../images/btnRegular.png) no-repeat scroll 0 0 !important;
}
.linkButtonDelete:hover
{
background: transparent url(/../images/btnHighlight.开发者_Python百科png) no-repeat scroll 0 0 !important;
}

And here is the problem: If I disable the linkbutton (LinkButtonDelete.Enabled = false;) and then hover over the linkbutton, the background image shows btnHighlight.png (instead of btnRegular.png). I tested this in IE9 and Chrome. Same effect.

Is there any chance I can apply a "disabled" style with CSS only (please no Javascript!)?

Thanks


I'm keeping my other answer because it would work as well, but if you want a purely CSS solution, look into Attribute Selectors which are supported starting with CSS 2.1. Assuming ASP.NET sets the disabled attribute, you could add something like so:

.linkButtonDelete[disabled="disabled"]:hover
{
background: something else;   
}


It sounds like it's acting exactly as you tell it to. It's showing the hover. If you don't want it to show the hover, when you are disabling the button, it sounds like you need to set the Class to something else and create a new class that doesn't have the hover.

LinkButtonDelete.Enabled = false;
//then
LinkButtonDelete.Attributes["class"] = "linkButtonDeleteDisabled"; // give it a new class

or

 LinkButtonDelete.CssClass = "linkButtonDeleteDisabled";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜