ibnLoki
ibnLoki

Reputation: 35

Asp.net button still disabled

I have a trouble with an ASP.NET form. I have a button on the page disabled and invisible on startup, and I enable it on an event. Here is the 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.

Upvotes: 2

Views: 1547

Answers (4)

Nagaraj S
Nagaraj S

Reputation: 13474

Use Enabled="false" And check your panel also

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

Upvotes: 0

Amarnath Balasubramanian
Amarnath Balasubramanian

Reputation: 9460

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

Upvotes: 0

Markus
Markus

Reputation: 22446

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.

Upvotes: 1

Learner
Learner

Reputation: 353

Try this code.

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

Hope this helps.

Upvotes: 0

Related Questions