简体   繁体   English

如何使ImageButton无法点击

[英]How to make ImageButton not clickable

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. 我在转发器中有许多ImageButton,根据每个记录,这些图像中的一些将是可点击的,而其他的,我已禁用该按钮以停止回发。

I have now changed the opacity of each image so that unless you are hovering on that imagebutton it will be 0.6. 我现在已经改变了每个图像的不透明度,所以除非你在那个图像按钮上盘旋,否则它将是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. 但是,由于禁用按钮现在导致我出现问题,我怎么可能只是停止按钮可点击/没有回发但允许使用其他属性。

try this: 尝试这个:

imagebutton.Attributes.Add("onclick","return false");
imagebutton.Style.Add("cursor","context-menu");

Different way using Css: 使用Css的不同方式:

In your css file add: 在你的css文件中添加:

.notclickable{
    cursor:text;    
}

And in DisableImageButton method add: 并在DisableImageButton方法中添加:

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

you can use CSS 你可以使用CSS

.imagebutton:disabled { .imagebutton:disabled {
opacity:0.7; 不透明度:0.7;
} }

check this out: 看一下这个:

http://www.w3schools.com/cssref/sel_disabled.asp http://www.w3schools.com/cssref/sel_disabled.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM