Howdy folks! I'm having a problem that is driving me nuts and I'm hoping someone here might have a solution. I'm making several custom web-forms controls in a Sitefinity project and so far most things seem to be working correctly. I have been able to add them as widgets, and I have been able to edit their public properties in the Sitefinity page edit-view no problem. When I edit these custom properties, they are correctly saved to the sf_control_properties table in my server (see screenshot1 and screenshot2). So far so good...however I am having a peculiar issue with programatically accessing the auto-generated control_id field in my control's code behind. As you can see in screenshot1: there is a unique control_id that refers to a particular instance of widget on a page. I would very much like to use that control_id to uniquely associate my own collection of items with a particular control. Effectively what I'm looking for is something like screenshot3. I want to be able to call a method on the code behind that will return the current control_id. It seems like this should be something extremely easy to do, but it has me completely stumped. I have tried searching through documentation and also entering a help ticket, but haven't had anything relevant turn up.
var currentPage = SiteMapBase.GetActualCurrentNode().Id;
var pageManager = PageManager.GetManager();
var currentPageNode = pageManager.GetPageNode(currentPage);
//retreive the page
var pages = App.WorkWith().Pages().LocatedIn(PageLocation.Frontend).Where(pt => pt.Id.Equals(currentPageNode.Id)).Get().FirstOrDefault();
//get the page data where controls are stored
var pageData = pages.Page;
var tempPage = pageManager.EditPage(pageData.Id);
//find particulat control by its name
var uControls = tempPage.Controls.Where(c => c.Caption ==
//get the control id saved in sf_control_peroperts
var control_id = uControls.Id;
var theseControls = pageData.Controls.Where(x => x.Caption ==
"Control Name Here"
var thisControl = theseControls.FirstOrDefault();
//find particulat control by its type
var uControls = tempPage.Controls.Where(c => c.ObjectType.StartsWith(
//loop trough all controls
var control_id = controls.Id;
I came up with a similar solution, but I have fewer steps and I'm not sure if the steps I've omitted are necessary. Specifically, I see that in your example you:
1) First lookup the page node GUID by calling SiteMapBase.GetActualCurrentNode().Id, but then you look it up again by retrieving the PageNode, and then you pass in currentPageNode.Id to retrieve the same PageNode again... why the repeated querying to retrieve the same data (the page node GUID)? Or is it different and I'm not picking up on the differences?
2) Once you've got the PageData object, you edit the page, creating a draft page, and iterate over the controls. Why don't you simply look in the PageData.Controls collection? Why create a draft page? Creating a draft page (i.e., calling pageManager.EditPage()) won't work while the page is locked, by the way. You'll get an exception.
You can see what I did in my thread. Is there some situation I'm not covering for by eliminating the steps mentioned above?