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

Forums / Developing with Sitefinity / Custom page properties

Custom page properties

9 posts, 0 answered
  1. Chris
    Chris avatar
    87 posts
    Registered:
    11 May 2010
    18 Jun 2010
    Link to this post
    I am trying to add some custom properties to pages. I know that SF does not really support custom page properties out of the box, but I have created a new database table and written code for saving and retrieving the custom property values, but I can't work out where to call my code from.

    All the posts on the forum about this topic seem to point to an article that no longer exists - http://sitefinity.habaneros.com/default/09-02-17/Page_Meta_Data_-_Intercepting_Sitefinity-769469583.aspx

    Can anyone tell me or give me a code sample demonstrating how I can achieve this?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    21 Jun 2010
    Link to this post
    Hi Chris,

    Such code should be added to the code behind of

    •  PagePropertiesEdit -you could use OnLoad or OnPreRender to call the code that retrieves the custom property data.
    • PagePropertiesInsert - when you click SaveButton, so you could subscribe to Click event. Your code will be executed after the base code.
    The control templates are located under Sitefinity/Admin/ControlTemplates/Pages folder. If you want to use these properties somewhere else you need to make the database queries to retrieve the correct value for Page-Property


    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Chris
    Chris avatar
    87 posts
    Registered:
    11 May 2010
    21 Jun 2010
    Link to this post
    I thought I probably needed to look at these controls however they don't have any code behind by default when I open my solution in Visual Studio (I have converted my SF web site to web app - I get "Unable to convert" errors for all the usre controls under the SiteFinity directory).

    I'm not sure how the page controls work. Do I need to create a view class and map it to the ascx in a similar way to how modules work?

    Thanks,

    Chris.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    21 Jun 2010
    Link to this post
    Hi Chris,

    These are just controls for which you need to create a code behind.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Chris
    Chris avatar
    87 posts
    Registered:
    11 May 2010
    21 Jun 2010
    Link to this post
    Thanks Ivan, looks as though this works.

    Chris.
  6. Chris
    Chris avatar
    87 posts
    Registered:
    11 May 2010
    21 Jun 2010
    Link to this post
    Hi again Ivan,

    Sorry but I've come up with another problem I don't know how to solve. In the code behind for these controls how do I know what the page ID is? I need to store the page ID alongside the value of my custom property so I can get it back again. Can you help?

    Thanks,

    Chris.
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    21 Jun 2010
    Link to this post
    Hello Chris,

    When you select a page its ID is appended to the QueryString, but you should better get the selected page from the PageEditor as shown below

    PagePropertiesEdit.ascx

    protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            Guid pageID = ((Telerik.Cms.Web.UI.PageEditor)(this.Parent.Parent.Parent.Parent.Parent.Parent)).SelectedPageId;
        
        }

    The properties get enabled when you create a page, so the correct place to add your properties is under PagePropertiesEdit.ascx template.


    Another option is subscribing for CmsManager.Executing and check the command name

    void CmsManager_Executing(object sender, Telerik.ExecutingEventArgs e)
     {
     
         if (e.CommandName == "CreatePage")
         {
           
     
         }
     }


    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. Chris
    Chris avatar
    87 posts
    Registered:
    11 May 2010
    22 Jun 2010
    Link to this post
    I struggled slightly with how best to set the properties when the page is first created in PagePropertiesInsert.ascx.

    I found that SelectedPageId is not set when I subscribe to the save button click when creating a page, and the Executing/Executed events are firing twice. Something funny is going on with the lifecycle that's preventing me from tracking whether I've already processed the Executing event (I set a property to true but the second time the event fires it is set back to false so I end up inserting duplicate rows in my table) so I've ended up with a hybrid solution...

    void SaveButton_Click(object sender, EventArgs e)
            {
                SaveButtonClicked = true;
            }
     
    void CmsManager_Executing(object sender, Telerik.ExecutingEventArgs e)
            {
                if (e.CommandName.Equals("CreatePage"))
                    CreatedPage = e.CommandArguments as CmsPage;
            }
     
    protected override void OnUnload(EventArgs e)
            {
                if (SaveButtonClicked && CreatedPage != null)
                    // save custom properties
                base.OnUnload(e);
            }

    However I'm sure there must be a better way. I don't feel comfortable at all using OnUnload for this purpose.
  9. Chris
    Chris avatar
    87 posts
    Registered:
    11 May 2010
    22 Jun 2010
    Link to this post
    I suppose I don't actually need to catch the save button click as catching the CreatePage command will tell me it's been clicked but I can't see how to process the command outside of OnUnload.
Register for webinar
9 posts, 0 answered