简体   繁体   中英

Hiding a linkbutton on the master page

I'm trying to show 2 link buttons in the master page, but these buttons should be Enable/Disable according to the content page. I already retrieve the information from the content page, and it works well, the only thing is that I can't turn enable the buttons once I have disabled them. I have tried several ways, but every attempt seems to do the same. Here is my code.

protected void Page_Load(object sender, EventArgs e)
{
    if (IsPostBack)
    {
        ASPxListBox listBoxSA = new ASPxListBox();

        listBoxSA = (ASPxListBox)ContentPanelHidden.FindControl("ASPxListBox2");

        if (listBoxSA != null)
        {
            if (listBoxSA.Items.Count > 0)
            {
                EnableButtons(true);
            }
            else
            {
                EnableButtons(false);
            }
        }
    }
    else
    {
        EnableButtons(false);
    }
}

public void EnableButtons(Boolean enable)
{
    btnNext.Enabled = enable;
    btnPrint.Enabled = enable;
}

PS. The boolean is changing its value, but the button is always disabled

因为使用的是is back back属性,所以一旦禁用它,就应该从当前页面进行回发,而且listBoxSA不应为null。

I would enclose these buttons in an update panel and tell the update panel to update itself after setting the Enabled property. That should update the buttons with only a partial page update.

HTML

    <asp:UpdatePanel ID="MyUpdatePanel" runat="server" UpdateMode="Conditional" ClientIDMode="Static">
        <ContentTemplate>
            ... buttons here ...
        </ContentTemplate>
    </asp:UpdatePanel>

CODE BEHIND

public void EnableButtons(Boolean enable)
{
    btnNext.Enabled = enable;
    btnPrint.Enabled = enable;
    MyUpdatePanel.Update();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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