开发者

Style disabled ASP.NET Linkbutton with background image

开发者 https://www.devze.com 2023-04-12 04:12 出处:网络
I am using a simple ASP.NET linkbutton control. <asp:LinkButton ID=\"LinkButtonDelete\" runat=\"server\" CssClass=\"linkButtonDelete\">Delete</asp:LinkButton>

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

精彩评论

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

关注公众号