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

Forums / Developing with Sitefinity / Using Sitefinity Admin ascx Controls

Using Sitefinity Admin ascx Controls

9 posts, 0 answered
  1. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    20 Sep 2009
    Link to this post
    I'd like to use some of the administration functionality on my own pages. For example, I'd like to create a form that includes the ~/Sitefinity/Admin/Pages/PagePropertiesEdit.ascx control.

    Is that possible? If so, can I get some sample code? I'm not sure how pass a PageID to the control, for example.

    Thanks,
    Jeff
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    20 Sep 2009
    Link to this post
    Hi Jeff,

    You can create a custom form with the same Textboxes as PagePropertiesEdit control template. You can get a page ID using one of the methods that CmsManager exposes. For more information and code samples, please take a look at Finding Pages

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    21 Sep 2009
    Link to this post
    Thanks Ivan but I'm trying to use the functionality built in to Sitefinity, not recreate it.

    Yes, I can create a bunch of text boxes and dropdowns and use that information to update the page information in the database. But it would be much simpler if I could drop one of controls in the Sitefinity/Admin/ControlTemplates directories onto a page and provide the control some basic parameters like PageID so that it can do its job.

    Is that possible or do I need to duplicate the functionality of these controls?

    Jeff
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    21 Sep 2009
    Link to this post
    Hello Jeff,

    You can try to use the code below which will return the selected page ID in PagePropertiesEdit.ascx

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

    I hope this helps.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    21 Sep 2009
    Link to this post
    OK, we're getting a little closer to what I'm trying to do.

    The difference is that I'm trying to effectively set the SelectedPageId property of the PageEditor, not find out what its value is. Of course, this is impossible as the property is read-only.

    Maybe a sample page would help demonstrate what I'm trying to do.

    I'm starting with a blank form and adding the Sitefinity PageEditor control:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="PagePropertyEditor.aspx.cs" Inherits="Pages_PagePropertyEditor" %> 
    <%@ Register Assembly="Telerik.Cms" Namespace="Telerik.Cms.Web.UI" TagPrefix="cc1" %> 
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     
    <html xmlns="http://www.w3.org/1999/xhtml"
    <head runat="server"
        <title></title
    </head> 
    <body> 
        <form id="form1" runat="server"
            <cc1:PageEditor runat="server" ID="PE"  /> 
        </form> 
    </body> 
    </html> 
     


    From here I'd like to:
      *  Give the PageEditor control the page ID and any other info it needs to pull up the page properties.
      *  Fire an event or call a method to make the PageEditor control save the information after the user makes changes.

    Is it possible to use Sitefinity admin controls in this way?
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    22 Sep 2009
    Link to this post
    Hello Jeff,

    1. You need to use SiteMapPanel together with PageEditor control. Otherwise you will not see any pages.
    2. You cannot set the selectedPageId, but you need to use it to modify a page.

    Below is a sample code of the code behind that you should have.


       protected void Page_Load(object sender, EventArgs e) 
        { 
            this.pageEditor.SiteMapPanelId = this.siteMap.ID; 
     
            if (!this.IsPostBack) 
            { 
                bool selectRoot = false
                string qs = Request.QueryString["select"]; 
                if (!String.IsNullOrEmpty(qs)) 
                { 
                    Guid id = new Guid(qs); 
                    try 
                    { 
                        this.pageEditor.Select(id); 
                        this.siteMap.SelectedPageID = id; 
                    } 
                    catch (PageNotExistException) 
                    { 
                        selectRoot = true
                    } 
                } 
                else if (Request.QueryString.Get("mode") != null && Request.QueryString.Get("mode").Equals("new")) 
                { 
                    this.pageEditor.Insert(Guid.Empty); 
                } 
                else 
                { 
                    selectRoot = true
                } 
                if (selectRoot) 
                { 
                    this.pageEditor.Select(Guid.Empty); 
                    this.siteMap.SelectedPageID = Guid.Empty; 
                } 
            } 
        } 

    Note that there will be a js errors, because the PageEditor control is not supposed to work as a public editor and the js cannot be loaded.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    22 Sep 2009
    Link to this post
    OK, so it sounds like I can't use the Sitefinity Admin controls in the way I'm describing. That is really all I was asking.

    I will find another way update the content.

    Thanks,
    Jeff
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    23 Sep 2009
    Link to this post
    Hello Jeff,

    "PageEditor control is not supposed to work as a public editor"  If you find a good approach you can add it to our Code Library. It will be great resource for our community.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  9. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    23 Sep 2009
    Link to this post
    Without access to the internal workings of these controls, that would be a frustrating exercise of trial-and-error. Understand that I'm not just interested in the PagePropertiesEdit.ascx control. I need some functionality from Generic Content, Image Library, etc.

    Going forward, I plan on replicating the UI functionality I need from scratch where necessary and jumping directly to the appropriate admin pages in Sitefinity where possible.

    Thanks for your help on this, though.

    Jeff
Register for webinar
9 posts, 0 answered