[SOLVED] How to make ImageButton not clickable

Issue

I have a number of ImageButtons within a repeater, depending on each record some of these images will be clickable and others, I have disabled the button to stop postback.

I have now changed the opacity of each image so that unless you are hovering on that imagebutton it will be 0.6. The trouble is, for those that I have disabled, obviously I cannot alter the opacity on/off hover.

Currently I am doing this:

    if (vessel.IsRegistered)
    {
        imagebuttonRegistration.ImageUrl = ("../Images/Icons/registrationApproved.gif");
        imagebuttonRegistration.CommandArgument = null;
        DisableImageButton(imagebuttonRegistration);                
        imagebuttonRegistration.ToolTip = GetLocalResourceObject("imageButRegistrationRegisteredText").ToString();
    }

public static void DisableImageButton(ImageButton imagebutton)
{
    imagebutton.Attributes.Remove("href");
    imagebutton.Attributes.Add("disabled","disabled");            
}

But as disabling the button is now causing me problems, how might I just stop the button being clickable/no postback but allow the other attributes to be used.

Solution

Different way using Css:

In your css file add:

.notclickable{
    cursor:text;    
}

And in DisableImageButton method add:

imagebutton.Attributes["class"] ="notclickable";

Answered By – Cezary

Answer Checked By – Timothy Miller (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *