简体   繁体   English

Asp.net按钮仍被禁用

[英]Asp.net button still disabled

I have a trouble with an ASP.NET form. 我在使用ASP.NET表单时遇到麻烦。 I have a button on the page disabled and invisible on startup, and I enable it on an event. 我在页面上有一个禁用且在启动时不可见的按钮,并在事件中启用它。 Here is the HTML : 这是HTML:

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

And the code : 和代码:

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

And the button is visible, but still disabled. 并且该按钮可见,但仍处于禁用状态。 Thank you 谢谢

Updated: 更新:

Thanks Marcus for the idea, the problem was that it is on a panel that was disabled . 感谢马库斯(Marcus)的想法,问题在于它在被禁用面板上。

The problem might be that the button is located on a Panel that is disabled. 问题可能在于该按钮位于禁用的面板上。 This will also disable to controls that are located on it. 这也将禁用位于其上的控件。 In order to enable the Button, enable the Panel or move the Button from the Panel. 为了启用按钮,启用面板或从面板移动按钮。

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

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

Try this code. 试试这个代码。

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

Hope this helps. 希望这可以帮助。

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

Button Code 按钮代码

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

Code behind: 后面的代码:

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;
        }

    }

This worked well 这很好

My guess of problem might be with the panel being disabled where the buttons are placed , try enabling that too..!! 我的问题的猜测可能是禁用放置 按钮面板 ,也尝试启用它。

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;
        }

    }

where pnlButtons is the name of the panel where buttons are placed. 其中pnlButtons是放置按钮的面板的名称。

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

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