Reputation: 630
I have page which contains 'base' usercontrol. This usercontrol needs to load usercontrols dynamically. I've written one of these controls for test, it's called ContentTemplate
and it's type is ContentTemplateType
.
In the Page_Load event of the 'base' usercontrol i've the next code: (ph - asp:PlaceHolder)
ph.Controls.Add(new LiteralControl(String.Format("<!-- ko if: {0} -->", cond)));
ph.Controls.Add(new ContentTemplate());
ph.Controls.Add(new LiteralControl("<!-- /ko -->"));
But in the end on the page i have only <!-- ko if: live == false -->
and <!-- /ko -->
lines.
I've tried the next code too:
ph.Controls.Add(Page.LoadControl(ContentTemplateType, null));
but with the same result. What i've done wrong?
Upvotes: 0
Views: 65
Reputation: 3125
Please use this
Control ctrl = Page.LoadControl("UserControlPath");
ph.Controls.Add(ctrl);
For more details visit Template Control Load
Upvotes: 1