Control container id's

Posted by Community Admin on 05-Aug-2018 11:30

Control container id's

All Replies

Posted by Community Admin on 30-Jun-2011 00:00

Hi There,

We are going to redo our templates and themes for our migrated site in 4.x. We will be using the layout control, my question is, for the page migration we will need to setup some mapping between the control's old container id in the 3.7 site and the new container id in the 4.x site, which will be a layout control. I see that you cannot implicity specifiy the ID of a layout control like you can with a contentplaceholder. How do I get hold of the ID of the layout control? We already worked out where to change the migration tool to facilitate the change in mapping old templates to new templates and themes, it is now just the control's on the page that is the issue.

Regards,
Jean Erasmus

Posted by Community Admin on 06-Jul-2011 00:00

Hello Jean,

Let me make sure I understand you correctly: there are two types of controls - PageControl and TemplateControl - the latter is used when adding a control to a page template. Both have a property ContainerId of type Guid. On the other hand the LayoutControl class has string property named PlaceHolder and a collection named Placeholders of type PlaceHoldersCollection which in turn is KeyedCollection<string, Control>.

What you ask is for a property similar to ContainerId but for Layout that should put a control in a layout "box", is this correct?

Best wishes,
Lubomir Velkov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 06-Jul-2011 00:00

Hi There,

That is correct. What we want to acheive is to say, html generic control in placeholder with ID "mainContent" on the 3.7 site must be added to a specified layout control on the 4.x site.

Regards,
Jean Erasmus

Posted by Community Admin on 12-Jul-2011 00:00

Hello Jean,

Here is a sample - it assumes that you already have created a template with 3 layouts and a published page named "p1" that uses this template.

var pageManager = PageManager.GetManager();           
            
            var pageData = pageManager.GetPageDataList().Where(p => p.Title == "p1" && p.Status == ContentLifecycleStatus.Live).First();
// we open the page for editting
            var pageDraft = pageManager.EditPage(pageData.Id, true);
//some controls
            var simpleText1 = new Literal() Text = "simpleText1" ;
            var simpleText2 = new Literal() Text = "simpleText2" ;
            var simpleText3 = new Literal() Text = "simpleText3" ;
 
            var pageTemplate = pageData.Template;
var templateControls = pageTemplate.Controls.Where(tc => tc.IsLayoutControl).ToList();
            var layout1 = templateControls[0];
            var layout2 = templateControls[1];
            var layout3 = templateControls[2];
// create the control objects           
            var draftControl1 = pageManager.CreateControl<PageDraftControl>(simpleText1, layout1.PlaceHolders[0]);
            var draftControl2 = pageManager.CreateControl<PageDraftControl>(simpleText2, layout2.PlaceHolders[0]);
            var draftControl3 = pageManager.CreateControl<PageDraftControl>(simpleText3, layout3.PlaceHolders[0]);
 
// we add the new controls to the edited page
            pageDraft.Controls.Add(draftControl1);
            pageDraft.Controls.Add(draftControl2);
            pageDraft.Controls.Add(draftControl3);
 
            pageManager.PublishPageDraft(pageDraft.Id, true);
            pageManager.SaveChanges();

This code will put a simple string literal into each of the layouts. Layout control can contain more than one place holder so you can check the PlaceHolders collection to get those.

Kind regards,
Pavel
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 13-Jul-2011 00:00

Hi There,

Thank you very much for the code, it will go a long way to help us out. It would have been nice to be able to assign ID's to layout controls, that way you could use findcontrol function to get the correct layout container, instead of having to know the control hierarchy.

Regards,
Jean Erasmus

This thread is closed