More in this section

Forums / Developing with Sitefinity / Programmatically on ASCX controls to a sitefinity page

Programmatically on ASCX controls to a sitefinity page

4 posts, 0 answered
  1. Joel
    Joel avatar
    4 posts
    Registered:
    24 Oct 2007
    18 Jun 2008
    Link to this post
    I'm importing data into Sitefinity and I've found the documentation on how to programmatically create a Sitefinity page and add a generic content control to the page. I have created a custom user control (ascx file) that I need to add to the page and set custom properties on it.  I've looking for some example code on how to add these types of controls based on the file path to a page that I've created through the API.  Thanks.

    Joel
  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    19 Jun 2008
    Link to this post
    Hi Joel,

    Here is an example how to add user controls to dynamically created pages:

    private void CreatePage(
        {  
            CmsManager manager = new CmsManager(); 
     
            ICmsPage userPage = manager.CreatePage("Company"); 
            userPage.Navigable = true
            userPage.MenuName = "Company"
     
            Telerik.Cms.Data.PageTemplate template = ((Telerik.Cms.Data.CmsTemplateContent)manager.GetTemplate("Default")).PageTemplate; 
            userPage.Staged.Template = template; 
     
            IStagedPage stage = userPage.Staged.CheckOut(); 
            stage.AddControl("TopMenu""~/Sitefinity/UserControls/Navigation/SitePanelbar.ascx""SitePanelbar1"); 
     
            userPage.Publish(); 
        } 

    Regarding setting the properties of the user control, it is not possible for now because an exception is thrown when you try to invoke the getter or setter of the property.

    All the best,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Joel
    Joel avatar
    4 posts
    Registered:
    24 Oct 2007
    20 Jun 2008
    Link to this post
    Thanks for the reply.  I was disappointed to find that you are not able to set properties on this type of control.  Since user controls are on of the main and easiest ways to extend Sitefinity I thought this would be better supported.  Is there a future time this will be corrected? 

    For this solution since the control was simple enough I rewrote is as a composite control that I could use more easily.  Too bad I didn't know this form the start I could have save a lot of time trying to figure it out.

    Joel
  4. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    24 Jun 2008
    Link to this post
    Hi Joel,

    We will contact you as soon as we find a solution for this issue. Unfortunately, we can't commit to any time frames.

    We are sorry for the inconvenience caused.

    Regards,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Register for webinar
4 posts, 0 answered