Disable ASP.NET ImageButton in non-IE Browsers
-
11-09-2019 - |
Question
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?
Solution
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" : "";
}
OTHER TIPS
This code works with image button (also how to enable again)
if (cash == true && terms == true)
{
checkOutImageButton.Attributes.Add("disabled", "disabled");
error = true;
}
else
{
checkOutImageButton.Attributes.Remove("disabled");
error = false;
}
Add or remove the following in your code-behind file, at the same spot you set ImageButton1.Enabled = false
.
ImageButton1.Attributes["disabled"] = "disabled";