Liran Friedman
Liran Friedman

Reputation: 4287

User control not added to panel via code?

I have a panel inside an update panel on my page which is pre-loaded with a user control, and I want to remove this control and add a new one instead (after a user does some action) I registered the control:

<%@ 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>

And for adding the new control I wrote this code:

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);

But the control is not added to the panel, I don't get any errors even in debug, it is just not there. I can't even see it in the html on view source.

Upvotes: 0

Views: 58

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460108

Perhaps because you have these lines:

filesHistory.ShowExportControl =
filesHistory.ShowSearchParams = false;

Try something like:

filesHistory.ShowExportControl = true;
filesHistory.ShowSearchParams = false;

Upvotes: 1

Related Questions