隐藏母版页上的链接按钮

时间:2015-08-05 18:14:37

标签: c# asp.net webforms

我试图在母版页中显示2个链接按钮,但这些按钮应该是根据内容页面启用/禁用。我已经从内容页面检索了信息,并且效果很好,唯一的一点就是我禁用了按钮后我就无法启用这些按钮。我尝试了几种方法,但每次尝试似乎也都这样做。这是我的代码。

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。布尔值正在更改其值,但始终禁用该按钮

2 个答案:

答案 0 :(得分:0)

因为你使用的是post back属性,一旦它被禁用,你应该从当前页面发回一个帖子,listBoxSA也不应该为null。

答案 1 :(得分:0)

我会将这些按钮括在更新面板中,并在设置Enabled属性后告诉更新面板自行更新。这应该仅通过部分页面更新来更新按钮。

HTML

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

代码背后

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