1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Add SimpleView to Page programmatically

Add SimpleView to Page programmatically

3 posts, 1 answered
  1. Dave
    Dave avatar
    37 posts
    Registered:
    26 Dec 2008
    05 Sep 2011
    Link to this post
    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
  2. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    07 Sep 2011
    Link to this post
    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!
    Answered
  3. Dave
    Dave avatar
    37 posts
    Registered:
    26 Dec 2008
    09 Sep 2011
    Link to this post
    Thank You, SelAromDoteNet! I made a mistake in my code, now it works with Your help!
3 posts, 1 answered