views:

601

answers:

2

I have an <asp:ImageButton /> which has its enabled property set to false.

This works in Internet Explorer, the button is not 'clickable', but in other browsers you can click it. However, nothing happens when you click the imagebutton in these other browsers.

How can I disable the ability to click the button in browsers outside of Internet Explorer?

A: 

Add or remove the following in your code-behind file, at the same spot you set ImageButton1.Enabled = false.

ImageButton1.Attributes["disabled"] = "disabled";
moomi
I look at the markup and that's exactly how it renders already.
Jack Marchetti
and isn't it Attributes.Add("disabled", "disabled");
Jack Marchetti
isn't it Attributes.Add("disabled","true"); ?
Mahesh Velaga
no, it's disabled
Jack Marchetti
Generally I use disabled="disabled" on html input elements (works great!), but I read some where that in backend you need something like Attributes.Add("disabled","true"); so just wanted to clear my doubt, Thanks
Mahesh Velaga
@JackM - this syntax Attributes["disabled"] = "disabled"; is perfectly valid.
Phaedrus
+2  A: 

If i understand correctly, the ImageButton is disabled, so it doesn't cause a post back. The issue is that the 'hand' cursor is still displayed in Firefox when putting the mouse over of the ImageButton. If this is the case you can change the cursor for the ImageButton like this:

<style type="text/css">
    .pointer
    {
        cursor:default;
    }
</style>

<asp:ImageButton ID="ImageButton1" runat="server" 
     ImageUrl="~/Images/image.bmp" Enabled="false" />

protected void Page_Load(object sender, EventArgs e)
{
    ImageButton1.CssClass = !ImageButton1.Enabled ? "pointer" : "";
}
Phaedrus
Won't this cause the poitner to always be default even when it's enabled?
Jack Marchetti
Good catch, you will have to dynamically add the CssClass property in code behind depending on if the ImageButton is enabled/disabled.
Phaedrus