我的页面上的更新面板中有一个面板,它预先加载了一个用户控件,我希望删除此控件并添加一个新控件(在用户执行某些操作后) 我注册了控件:
<%@ Register src="~/UserControls/FilesControl.ascx" tagname="FilesControl" tagprefix="files" %>
<asp:Panel ID="pnlFiles" CssClass="selected_tab" runat="server" ClientIDMode="Static">
<files:FilesControl runat="server" ID="filesControl" ShowSearchParams="false" ShowExportControl="false" />
</asp:Panel>
为了添加新控件我编写了这段代码:
pnlFiles.Controls.Clear();
FilesControl filesHistory = (FilesControl)LoadControl("~/UserControls/FilesControl.ascx");
filesHistory.ShowExportControl =
filesHistory.ShowSearchParams = false;
InitHistoryControl<FilesControl>(filesHistory, daysBack, true); //Sets a datasource to a grid view in the control
pnlFiles.Controls.Add(filesHistory);
但控件没有添加到面板中,即使在调试中也没有出现任何错误,它只是不存在。我甚至无法在html视图源中看到它。
答案 0 :(得分:1)
也许是因为你有这些界限:
filesHistory.ShowExportControl =
filesHistory.ShowSearchParams = false;
尝试类似:
filesHistory.ShowExportControl = true;
filesHistory.ShowSearchParams = false;