1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / For Simple User Controls, What Should We Inherit From

For Simple User Controls, What Should We Inherit From

8 posts, 0 answered
  1. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    27 Feb 2012
    Link to this post
    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
  2. Svetoslav Petsov
    Svetoslav Petsov avatar
    456 posts
    Registered:
    24 Sep 2012
    29 Feb 2012
    Link to this post
    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 

    Greetings,
    Svetoslav Petsov
    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
  3. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    29 Feb 2012
    Link to this post
    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
  4. Yosief
    Yosief avatar
    27 posts
    Registered:
    20 Mar 2008
    01 Mar 2012
    Link to this post
    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
  5. Svetoslav Petsov
    Svetoslav Petsov avatar
    456 posts
    Registered:
    24 Sep 2012
    02 Mar 2012
    Link to this post
    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 

    All the best,
    Svetoslav Petsov
    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
  6. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    13 Mar 2012
    Link to this post
    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.}

    If you execute this it throws and exception:  System.NotSupportedException: Specified method is not supported.(this comes from line 5)

    So this is going nowhere. I'm going to ask the question again.
    We have a control (think of your blog view component) which has to change the title, description and keywords dynamically depending on what is being loaded into the control at runtime. I.e. we're NOT looking to change the title permanently and have it saved to the SF database.

    In the past we used InternalPage which you guys have politely made dissappear so now we're looking for another way to do this. you guys can clearly do it with the blog/news module, so surely it can be done.

    Does this maybe help, perhaps now you can provide a better answer?

    Jacques
  7. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    13 Mar 2012
    Link to this post
    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.}

    If you execute this it throws and exception:  System.NotSupportedException: Specified method is not supported.(this comes from line 5)

    So this is going nowhere. I'm going to ask the question again.
    We have a control (think of your blog view component) which has to change the title, description and keywords dynamically depending on what is being loaded into the control at runtime. I.e. we're NOT looking to change the title permanently and have it saved to the SF database.

    In the past we used InternalPage which you guys have politely made dissappear so now we're looking for another way to do this. you guys can clearly do it with the blog/news module, so surely it can be done.

    Does this maybe help, perhaps now you can provide a better answer?

    Jacques
  8. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    16 Aug 2017
    16 Mar 2012
    Link to this post
    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();
                    }
                }

    I have replied to the support thread discussing the same issue, and for your convenience you can find below
    our response as well:

    "1) The title of the dynamic news page doesn't have a SEO friendly title meta tag.

     Actually the described behavior is by design. Sitefintiy ContentView widgets (e.g. Events, Blogs, News etc.) have a public property called PageTitleMode which controls this behavior.
    By default it is set to replace the page title with the title of the first content item in the widget, however you can change this by Editing the widget's advanced settings. For your convenience I've made a screenshot demonstrating the location of this setting. You can choose among several modes here:
    Append- the content title will be appended to the page title
    Replace
    - the default setting, where the page title is replaced with the content title
    DoNotSet
    - content title will not be included in the page title


    2) There are no options to specify title, description and other meta information per news item.

    This request is logged internally. However, it is with lower priority as of now and its implementation is not 100% sure. This is why we didn't commit it publicly. 
    Most of our customers are relying on the title and content of the news to boost SEO. Meta description is rarely used. To test this assumption we have logged this request to our PITs system on this link 5842. Based on the popularity among the community we may raise the priority of this task. "


    Greetings,
    Boyan Barnev
    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
8 posts, 0 answered