0
votes

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?

1
Not clear what you want to achieve can you tell us more briefly what you want to achieve and whats not happening? - Jalpesh Vadgama
I want ContentTemplate usercontrol to be rendered between <!-- ko --> tags - LbISS

1 Answers

1
votes

Please use this

Control ctrl = Page.LoadControl("UserControlPath");

ph.Controls.Add(ctrl);

For more details visit Template Control Load