隐藏母版页上的链接按钮
Hiding a linkbutton on the master page
我试图在母版页中显示 2 个 link 按钮,但根据内容页,这些按钮应该是 Enable/Disable。我已经从内容页面检索了信息,并且效果很好,唯一的问题是一旦我禁用了按钮,我就无法启用它们。我尝试了几种方法,但每次尝试似乎都是一样的。这是我的代码。
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。布尔值正在更改其值,但按钮始终处于禁用状态
因为您使用的是 post 返回 属性,一旦它被禁用,您应该从当前页面返回 post 并且 listBoxSA 不应该为空。
我会将这些按钮包含在更新面板中,并告诉更新面板在设置启用 属性 后自行更新。那应该只更新部分页面更新按钮。
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();
}
我试图在母版页中显示 2 个 link 按钮,但根据内容页,这些按钮应该是 Enable/Disable。我已经从内容页面检索了信息,并且效果很好,唯一的问题是一旦我禁用了按钮,我就无法启用它们。我尝试了几种方法,但每次尝试似乎都是一样的。这是我的代码。
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。布尔值正在更改其值,但按钮始终处于禁用状态
因为您使用的是 post 返回 属性,一旦它被禁用,您应该从当前页面返回 post 并且 listBoxSA 不应该为空。
我会将这些按钮包含在更新面板中,并告诉更新面板在设置启用 属性 后自行更新。那应该只更新部分页面更新按钮。
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();
}