Tuesday, December 31, 2013

Disabling ASP LinkButton controls in newer versions of Internet Explorer

Since IE 10, I have noticed that when a LinkButton control is disabled (Enabled="False"), the rendered link is not grayed out like it used to be and seemingly should be.  The link is disabled for all intents and purposes, but just appears to be enabled.  This can cause confusion to users if you rely on this mechanism.  The quick fix has always been "compatibility view" in IE, but this is being phased out over time by Microsoft as we get newer version of Internet Explorer.

Interestingly enough, the html rendered is the same.  You still get an anchor tag with the disabled attribute set to "disabled".  It is the browser that is reacting differently to this tag.  IE no longer styles by default an anchor tag with this particular attribute the way you expect (i.e. "grayed out").  You are forced to provide the css to render in this scenario.  The following css should style your LinkButton like the good ole days.
    a[disabled="disabled"] {
        color: gray;
        text-decoration: none;
    }
    a[disabled="disabled"]:hover {
        color: gray;
        text-decoration: none;
    }
Now, maybe you can finally turn off compatibility view!

No comments:

Post a Comment