2012-10-18 71 views
8

所以我有一個按鈕,目前設置爲禁用,並在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?

感謝

+0

,允許它被禁用,但在瀏覽器中它不灰色出來 – TheLifeOfSteve

+0

每個瀏覽器都有自己的默認樣式。然而,你可以強制你自己的風格。爲此,您必須創建自定義CSS類並將其應用於您的意願 – JSantos

+0

什麼是ESTableHeaderL的CSS?這可能會導致問題,因爲每個瀏覽器都有一些默認的禁用按鈕樣式。可能你已經以某種方式重新定義了它 –

回答

8

:disabled selector可以用CSS3使用

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

瀏覽器兼容性:

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

對於ASP.NET:

添加的CssClass屬性爲您服務器-SI de按鈕並將其引用到包含上述CSS的類。

+0

可能還想添加'input [type =「submit」]:disabled'。 – jrummell

+0

請原諒我的無知,但是如何將樣式應用於asp.net中的對象 – TheLifeOfSteve

+1

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

1

你可以編程如果禁用

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

CSS指定一個css類

.disabledbutton{ 
    background-color:#ddd; 
} 
+0

我可以在手邊做嗎?我有很多表內的按鈕實際上按鈕工作作爲禁用,但在視覺上,他們被啓用,即9禁用其禁用和ie11其啓用。我知道按鈕的ID。反正有沒有做從CSS只是不想使用代碼隱藏 –

0

Framerwork 4渲染控制不同。將下面的內容添加到您的we.config中,並且禁用的按鈕將照常變灰。

<pages controlRenderingCompatibilityVersion="3.5"/> 
0

無需使用自定義CSS類(對樣式表無任何影響)的快速方法,可以在後面的代碼中完成。下面我們來設置你的下載按鈕的背景顏色爲綠色(我認爲這是綠色的,我是色盲: - |):

DownloadButton.Attributes.Add("style", "background-color:#28C523");