For Simple User Controls, What Should We Inherit From
If we are developing simple user controls, which Sitefinity object is best to inherit from?
And...
If we are developing simple user controls that need to be able to change the page Title, description and keywords, which Sitefinity control is best to inherit from?
Thanks
Jacques
Hi Jacques,
If you only need a reference to the current Page and its events, all that you need is a user control - a regular .ascx control that inherits from System.Web.UI.UserControl. Then on its Page_Load event, you can get the current Page object (with this.Page) or get the current Sitefinity Page Node with SiteMapBase.GetActualCurrentNode() method. This control can be easily used within Sitefinty by registering it as a widget inside the pages toolbox, using a relative path to it. More information on how to do this can be found in the following article from our documentation:
http://www.sitefinity.com/documentation/documentationarticles/adding-controls-to-the-toolbox
Hi Svetoslav,
Does SiteMapBase.GetActualCurrentNode() give you the ability to dynamically change the page title, description and meta data? We have a dynamic page and need to be able to adjust those elements values.
Regards,
Jacques
Hi Svetoslav
We went with SiteMapBase.GetActualCurrentNode() option. This apparently gets a 'PageSiteNode' object. But it does not have a collection of controls that are within the Sitefinty page.
Is there any class in your SF 4.x assemblies that directly or indirectly gets the collection of controls in a SF page, preferably of the 'System.Web.UI.Control' type or any compatible type such as UserControl?
Thanks in advance for the feedback
Yosief
Hello,
After getting the Page Node, you can get its PageData (can be accessed through the Page property of the node). The PageData holds a collection of the controls of the page. Here's a section of our documentation that has all of the samples that you need - for selecting the PageData, changing the page's title and adding controls to the page:
http://www.sitefinity.com/documentation/documentationarticles/developers-guide/sitefinity-essentials/pages/adding-and-removing-controls
Hi Svetoslav,
First, a couple of points:
1. SiteMapBase.GetActualCurrentNode() does not return a Page Node it returns a PageSiteNode
2. PageSiteNode does not have a Property called Page
(So you're previous posts were misleading and ended up with us wasting a lot of time)
Where we're at now with this question that we started on Feb 27th.
Our user control inherits from a custom control which has a method called SetCmsPageTitle.
The code now looks like this:
1.
public
void
SetCmsPageTitle(
string
title)
2.
3.
//CurrentInternalPage.NewTitle = title;
4.
PageSiteNode node = SiteMapBase.GetActualCurrentNode();
5.
node.Title =
"Test Title"
;
6.
Hi Svetoslav,
First, a couple of points:
1. SiteMapBase.GetActualCurrentNode() does not return a Page Node it returns a PageSiteNode
2. PageSiteNode does not have a Property called Page
(So you're previous posts were misleading and ended up with us wasting a lot of time)
Where we're at now with this question that we started on Feb 27th.
Our user control inherits from a custom control which has a method called SetCmsPageTitle.
The code now looks like this:
1.
public
void
SetCmsPageTitle(
string
title)
2.
3.
//CurrentInternalPage.NewTitle = title;
4.
PageSiteNode node = SiteMapBase.GetActualCurrentNode();
5.
node.Title =
"Test Title"
;
6.
Hello Jacques,
The IDs of the PageSiteNode which representes the PageNode in the SiteMap and the actual pageNode are the same, so you can use this and get the PageNode by the corresponding PageSiteNode Id. This would allow you to access the PageData properties, for example:
if
(!
this
.IsDesignMode() || !
this
.IsPreviewMode())
var siteNode = SiteMapBase.GetActualCurrentNode();
if
(siteNode !=
null
)
var mng = PageManager.GetManager();
var node = mng.GetPageNode(siteNode.Id);
var data = node.Page;
data.HtmlTitle =
"test"
;
data.Description =
"description"
;
mng.SaveChanges();