我的按钮上的:disabled属性似乎不起作用

时间:2018-05-03 22:18:35

标签: c# css asp.net button

我在禁用按钮的样式时遇到问题 启用按钮工作,悬停工作,但禁用按钮恢复默认值?式:

CSS:

.smlbutton:enabled{
    color: #fff;
    background-color: #1d60ff;
    height: 20px;
    width: 18px;
    padding: 0px;
    border: none 0px transparent;
    font-size: 7px;
    font-weight: lighter;
    webkit-border-radius: 20px 10px 10px 10px;
    -moz-border-radius: 9px 10px 10px 10px;
    border-radius: 5px 20px 20px 20px;
}

.smlbutton:hover{
    color: #fff;
    background-color: #1d60ff;
    height: 22px;
    width: 18px;
    padding: 0px;
    border: none 0px transparent;
    font-size: 7px;
    font-weight: lighter;
    webkit-border-radius: 20px 10px 10px 10px;
    -moz-border-radius: 9px 10px 10px 10px;
    border-radius: 5px 20px 20px 20px;
}
 .smlbutton:disabled,.smlbutton.disabled{
    color: #fff;
    background-color: #1d60ff;
    height: 200px;
    width: 18px;
    padding: 0px;
    border: none 0px transparent;
    font-size: 7px;
    font-weight: lighter;
    webkit-border-radius: 20px 10px 10px 10px;
    -moz-border-radius: 9px 10px 10px 10px;
    border-radius: 5px 20px 20px 20px;

ASPX:

<asp:TemplateField HeaderText="Approval Drawings Approved" Visible="true">
                                <ItemTemplate>
                                    <asp:TextBox ID="tbApprovals" runat="server" Text='<%# Bind("Approvals", "{0:MM/dd/yy}") %>' AutoPostBack="true" Enabled="true" OnTextChanged="tbDate_OnTextChangeApprovals" Width="100px"></asp:TextBox>
                                    <ajaxToolkit:CalendarExtender ID="tbApprovals_CalendarExtender" runat="server" TargetControlID="tbApprovals" />
                                    <asp:Button ID="btnApprovalsConvertToBaseline" class="smlbutton" runat="server" Text="B." OnClick="btnApprovalsConvertToBaseline_Click" Enabled="FALSE" />
                                    <asp:Button ID="btnApprovalsCompleteTask" class="smlbutton" runat="server" Text="D." OnClick="btnApprovalsCompleteTask_Click" Enabled="FALSE" />
                                    <asp:Button ID="btnApprovalsCompleteTaskOnTime" class="smlbutton" runat="server" Text="DOT" OnClick="btnApprovalsCompleteTaskOnTime_Click" Enabled="FALSE" />
                                </ItemTemplate>
                            </asp:TemplateField>

我使用此c#

启用按钮
   try
    {
        TextBox tempApprovals = (TextBox)e.Row.Cells[9].FindControl("tbApprovals");
        DateTime myDateApprovals = DateTime.ParseExact(tempApprovals.Text.ToString(), "yyyy-MM-dd",
                                   System.Globalization.CultureInfo.InvariantCulture);

        if (myDateApprovals <= DateTime.Now.Date && e.Row.Cells[10].Text != "Actual")
        {
            tempApprovals.ForeColor = System.Drawing.Color.Red;
            tempApprovals.Font.Bold = true;
        }
        Button btnApprovals = (Button)e.Row.Cells[9].FindControl("btnApprovalsConvertToBaseline");
        Button btnApprovals2 = (Button)e.Row.Cells[9].FindControl("btnApprovalsCompleteTask");
        Button btnApprovals3 = (Button)e.Row.Cells[9].FindControl("btnApprovalsCompleteTaskOnTime");

        if (e.Row.Cells[10].Text.ToString() == "Forecast")
        {
            btnApprovals.Enabled = true;
        }

        if (e.Row.Cells[10].Text.ToString() == "Baseline")
        {
            btnApprovals.Enabled = false;
            btnApprovals2.Enabled = true;
            btnApprovals3.Enabled = true;
        }

        if (e.Row.Cells[10].Text.ToString() == "Adjusted")
        {
            btnApprovals.Enabled = false;
            btnApprovals2.Enabled = true;
            btnApprovals3.Enabled = true;
        }

        if (e.Row.Cells[10].Text.ToString() == "Actual")
        {
            btnApprovals2.Enabled = false;
            btnApprovals3.Enabled = false;
        }
    }
    catch { }

}

1 个答案:

答案 0 :(得分:0)

您不需要为每个伪类设置样式。相反,让我们继承父母。

.smlbutton {
    color: #fff;
    background-color: #1d60ff;
    height: 22px;
    width: 18px;
    padding: 0px;
    border: none 0px transparent;
    font-size: 7px;
    font-weight: lighter;
    webkit-border-radius: 20px 10px 10px 10px;
    -moz-border-radius: 9px 10px 10px 10px;
    border-radius: 5px 20px 20px 20px;
}

    .smlbutton:disabled,
    .smlbutton[disabled] {
        background-color: #0f0;
    }

    .smlbutton:hover {
        background-color: #f00;
    }