Asp.net

按鈕已禁用但看起來很活躍

  • June 5, 2017

所以我有一個目前設置為禁用的按鈕,在 IE 中它是灰色的,但在 Firefox、Chrome 和 Safari 中,它被禁用但看起來仍然處於活動狀態。

按鈕程式碼

<tr valign="middle">
   <td colspan="2" style="width: 100%">
       <asp:Button ID="DownloadButton" runat="server" Text="Download" Width="85px" CssClass="ESTableHeaderL" OnClick="DownloadButton_Click" />
   </td>      
 </tr> 

我的程式碼在後面

protected void DownloadButton_Click(object sender, EventArgs e)
{        
   if (ddBusinessMonth.Items.Count == 0)
   {
       DownloadButton.Enabled = false;
       ShowClientMessageBox("No Data found for downloading");
   }
....

}

有什麼辦法可以讓它看起來和 IE 一樣嗎?

謝謝

: disabled 選擇器可以與 CSS3 一起使用

input[type="button"]:disabled
{
background:#dddddd;
}

瀏覽器兼容性:

IE8+ FF1.5+ SA3.1+ OP9.2+ CH2+

對於 ASP.NET:

將 CssClass 屬性添加到伺服器端按鈕並將其引用到包含上述 CSS 的類。

如果它被禁用,您可以以程式方式分配一個 CSS 類

if (ddBusinessMonth.Items.Count == 0)
   {
       DownloadButton.Enabled = false;
       DownloadButton.CssClass = "disabledbutton";
       ShowClientMessageBox("No Data found for downloading");
   }

css

.disabledbutton{
   background-color:#ddd;
}

引用自:https://stackoverflow.com/questions/12957924