简体   繁体   中英

How to change asp button color when disabled, by default button will be disabled on UI

<asp:Button ID="btnSubmit" runat="server" Text="Save" 
     CssClass="buttonNormal buttonChange" OnClick="submit_Click" 
     Enabled="false" ToolTip="Please click on the left button to enable save" />

On startup save button will be rendered as disabled, on click of other button, the "Save" button will be enabled.

Functionality is working as expected, but there is no difference in button view whether it's enabled or disabled.

Cannot write the color change logic in CS file because this button will be rendered on start of application.

Can someone help with this issue?

TIA, Kal.

In your submit_Click function, you could add;

using System.Drawing;
...
if(btnSubmit.Enabled == "False"){
   btnSubmit.BackColor = Color.Blue; // or btnSubmit.BackgroundColor = Color.Blue;
}
else{
   btnSubmit.BackColor = Color.Grey; // or btnSubmit.BackgroundColor = Color.Grey;
}

You can initially set the color like this;

<asp:Button BackgroundColor="Blue" ID="btnSubmit" runat="server" Text="Save" 
     CssClass="buttonNormal buttonChange" OnClick="submit_Click" 
     Enabled="false" ToolTip="Please click on the left button to enable save" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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