简体   繁体   English

禁用时如何更改asp按钮颜色,默认情况下按钮将在UI上禁用

[英]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.无法在 CS 文件中写入颜色更改逻辑,因为此按钮将在应用程序启动时呈现。

Can someone help with this issue?有人可以帮助解决这个问题吗?

TIA, Kal. TIA,卡尔。

In your submit_Click function, you could add;在您的提交_单击 function 中,您可以添加;

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" />

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

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