我正在尝试使用linkbutton中的命令参数动态引用代码隐藏文件中的Panel。链接按钮和面板代码是:
<asp:Panel ID="pnlLeaseControls" runat="server">
<asp:LinkButton ID="btnLessorEmail" CssClass="btn btn-default" runat="server" CommandArgument="pnlLessorEmail" OnCommand="displayEmailSection">Lessor</asp:LinkButton>
<asp:LinkButton ID="btnLesseeEmail" CssClass="btn btn-default" runat="server" CommandArgument="pnlLesseeEmail" OnCommand="displayEmailSection">Lessee</asp:LinkButton>
</asp:Panel>
参考该小组的方法如下:
public void displayEmailSection(object sender, EventArgs e)
{
LinkButton ButtonCommandArg = (LinkButton)sender;
string TheCommand = ButtonCommandArg.CommandArgument.ToString();
Panel thePanel;
thePanel = Page.FindControl(TheCommand) as Panel;
thePanel.Visible = true;
}
当我运行代码时,它告诉我面板有一个空对象引用。
谢谢,任何帮助都会很棒。