Created
April 24, 2012 23:42
-
-
Save SitefinityGuru/2484655 to your computer and use it in GitHub Desktop.
Programmatically Adding Controls to a Sitefinity Page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var control = new NewsView(); | |
var pageControl = pageManager.CreateControl<PageControl>(control, placeHolder); | |
pageNode.Page.Controls.Add(pageControl); | |
pageManager.SaveChanges(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add First Control | |
var ctrl = pageManager.CreateControl<PageControl>("~/Widgets/FirstControl.ascx", "Content"); | |
pageNode.Page.Controls.Add(ctrl); | |
// Get first control id | |
var lastID = ctrl.Id; | |
// add second control, link to first control | |
ctrl = pageManager.CreateControl<PageControl>("~/Widgets/SecondControl.ascx", "Content"); | |
ctrl.SiblingId = lastID; | |
newPage.Page.Controls.Add(ctrl); | |
// update control id to last added | |
lastID = ctrl.Id; | |
// add final control, link to previous control | |
ctrl = pageManager.CreateControl<PageControl>("~/Widgets/LastControl.ascx", "Content"); | |
ctrl.SiblingId = lastID; | |
newPage.Page.Controls.Add(ctrl); | |
pageManager.SaveChanges(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ctrl = pageManager.CreateControl<PageControl>("~/Widgets/MyControl.ascx", "Content"); | |
pageNode.Page.Controls.Add(ctrl); | |
pageManager.SaveChanges(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment