Add SimpleView to Page programmatically

Posted by Community Admin on 04-Aug-2018 12:36

Add SimpleView to Page programmatically

All Replies

Posted by Community Admin on 05-Sep-2011 00:00

Hello there!

I just want to know, if there's a way to add a SimpleView-Control to a Page programmatically?

I've used the Testimonials Intra-Site Module Sample as base for a own module. Since it is easier to install, I want to use SimpleView for the Backend-Page-Controls, instead of ascx an code-behind. It is possible to add the SimpleView as PageControl programmatically to the Backend-Page and how?

Thanks in advance, Dieter

Posted by Community Admin on 07-Sep-2011 00:00

You can certainly add compiled controls based on SimpleView programmatically. Instead of creating the control with a path to an ascx file, instead create it using an instance of the control itself.

For example:

var control = new NewsView();
var pageControl = pageManager.CreateControl<PageControl>(control, placeHolder);
page.Page.Controls.Add(pageControl);
pageManager.SaveChanges();

hope this is helpful!

Posted by Community Admin on 09-Sep-2011 00:00

Thank You, SelAromDoteNet! I made a mistake in my code, now it works with Your help!

This thread is closed