繁体   English   中英

Asp.net按钮仍被禁用

[英]Asp.net button still disabled

我在使用ASP.NET表单时遇到麻烦。 我在页面上有一个禁用且在启动时不可见的按钮,并在事件中启用它。 这是HTML:

<asp:Button ID="btnSaveQ37" runat="server" Text="Save and continue" ValidationGroup="save" OnClick="btnSave_Click" CssClass="saveButton" Visible="false" />

和代码:

                btnSaveQ37.Enabled = true;
                btnSaveQ37.Visible = true;

并且该按钮可见,但仍处于禁用状态。 谢谢

更新:

感谢马库斯(Marcus)的想法,问题在于它在被禁用面板上。

问题可能在于该按钮位于禁用的面板上。 这也将禁用位于其上的控件。 为了启用按钮,启用面板或从面板移动按钮。

使用Enabled="false"并检查您的panel

<asp:Button ID="btnButton" runat="server" Text="Button" Enabled="false" />

试试这个代码。

<script type="text/javascript">
    window.onload = function callButtonClickEvent() {
        document.getElementById('<%=btnSaveQ37.ClientId %>').click();
    }
</script>

希望这可以帮助。

<tr>
        <td style="width:30%; text-align:right;">
            <asp:Label ID="Label1" runat="server">Drop Down List 1</asp:Label>
        </td>
        <td style="width:30%; text-align:left;">
            <asp:DropDownList ID="ddl1" runat="server" ValidationGroup="save" AppendDataBoundItems="true" AutoPostBack="true" Width="100%" OnSelectedIndexChanged="ddl1_SelectedIndexChanged">
                <asp:ListItem Text="" ></asp:ListItem>
                <asp:ListItem Text="Value 1" Value="1"></asp:ListItem>
                <asp:ListItem Text="Value 2" Value="2"></asp:ListItem>
            </asp:DropDownList>
        </td>
        <td></td>
    </tr>

按钮代码

<asp:Button ID="btnSaveQ37" runat="server" Text="Save and continue" ValidationGroup="save" CssClass="saveButton" Visible="false" Enabled="false" /></td>

后面的代码:

protected void ddl1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddl1.SelectedValue == "1")
        {
            btnSaveQ37.Enabled = true;
            btnSaveQ37.Visible = true;

        }
        else
        {
            btnSaveQ37.Enabled = false;
            btnSaveQ37.Visible = false;
        }

    }

这很好

我的问题的猜测可能是禁用放置 按钮面板 ,也尝试启用它。

protected void ddl1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddl1.SelectedValue == "1")
        {
            pnlButtons.Enabled = true;
            btnSaveQ37.Enabled = true;
            btnSaveQ37.Visible = true;

        }
        else
        {
            pnlButtons.Enabled = false;
            btnSaveQ37.Enabled = false;
            btnSaveQ37.Visible = false;
        }

    }

其中pnlButtons是放置按钮的面板的名称。

暂无
暂无

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

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