Disabled button with a alert is clickable in IE8 (

2019-03-03 08:08发布

问题:

I have disabled a link button and image button(which is inside a link button so that I can show a Alert) and it works fine in Chrome, but when I open it in IE8 the image is disabled but when i click it it shows the popup('Are you sure you want to delete this User?'). Why am I getting this error in IE8 and IE7, how can I fix this.

  <asp:LinkButton ID="lnk_DeleteUser" Enabled="false" 
    ToolTip="Delete" runat="server" 
   OnClientClick="return confirm('Are you sure you want to delete this User?')">
  <asp:ImageButton ID="Img_del" Enabled="false" 
      src="Styles/Images/icon_delete.png" 
      OnClick="imgbtn_UserDeleteClick"                                            
     runat="server" Style="border-style: none" alt="Delete User" /></asp:LinkButton>

Code from view source:

 <a onclick="return confirm(&#39;Are you sure you want to delete this User?&#39;);"
 id="ctl00_MainContent_UserTable_ctl02_lnk_DeleteUser" title="Delete User" 
class="aspNetDisabled"><input type="image" name="ctl00$MainContent$UserTable$ctl02
$Img_del" id="ctl00_MainContent_UserTable_ctl02_Img_del" disabled="disabled" 
title="You don&#39;t have permission to delete users" class="aspNetDisabled" 
src="Styles/Images/icon_delete.png" alt="Delete User" src="" 
style="border-style: none" /></a>

回答1:

Why not merge the ImageButtons purpose with the LinkButton? (or vice versa...)

<asp:LinkButton runat="server" ID="lBtnDeleteUser" OnClick="lBtnDeleteUser_Click"
OnClientClick='return confirm("Are you sure you want to delete this User?")'
style="display: block; background-image: url('Styles/Images/icon_delete.png');
width: widthOficon_delete.pngInPixels; height: heightOficon_delete.pngInPixels;"
ToolTip="Delete" />


回答2:

<asp:ImageButton ID="Img_del" runat="server" Text="Delete" ImageUrl="Styles/Images/icon_delete.png"
                                AlternateText="Delete" OnClientClick='return confirm("Are you sure you want to delete this item?");' OnClick="imgbtn_UserDeleteClick"/>

I solved it by using pop up in Image button [Learnt a new thing that HTML does not have a disabled attribute for links]