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

Forums / Developing with Sitefinity / Custom InternalPage and Preview Mode

Custom InternalPage and Preview Mode

5 posts, 0 answered
  1. Ivan
    Ivan avatar
    51 posts
    Registered:
    22 Aug 2007
    19 Aug 2010
    Link to this post
    Hi All,

    I have created a custom InternalPage where I override the OnPreRender method to look up a custom page attribute and set a css class based on that value.  The code works correctly when the cms page mode is "Live".  However, in preview mode it does not fire.  This is causing inconsistent css settings when the page is staged versus published.

    Is this a known issue or have I configured something incorrectly?  This is causing an issue for my QA team,

    Any help would be appreciated.  Thanks in advance.
    -Ivan
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    19 Aug 2010
    Link to this post
    Hello Ivan,

    PreRender, Render, AddHeaderControls if InternalPage class are not called when you preview a page. You have to create a custom class that inherits from Telerik.Cms.Web.FormAdapter


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI.HtmlControls;
     
    /// <summary>
    /// Summary description for TelerikCmsWebFormAdapterCustom
    /// </summary>
    public class TelerikCmsWebFormAdapterCustom : Telerik.Cms.Web.FormAdapter
    {
        public TelerikCmsWebFormAdapterCustom()
        {
            //
            // TODO: Add constructor logic here
            //
        }
     
        protected override void OnPreRender(EventArgs e)
        {
     
            base.OnPreRender(e);
     
            HttpContext context = HttpContext.Current;
            if (context.Request.QueryString["cmspagemode"] == "preview")
            {
                var myCSS = new HtmlLink();
                myCSS.Href = "~/somecss1.css";
                myCSS.Attributes.Add("rel", "stylesheet");
                myCSS.Attributes.Add("type", "text/css");
                Page.Header.Controls.Add(myCSS);
            }
        }
    }

    and replace the default one in App_Browsers/BrowserFile.browser

    <controlAdapters>
         <!--<adapter controlType="System.Web.UI.HtmlControls.HtmlForm" adapterType="Telerik.Cms.Web.FormAdapter, Telerik.Cms" />-->
         <adapter controlType="System.Web.UI.HtmlControls.HtmlForm" adapterType="TelerikCmsWebFormAdapterCustom, App_Code"/>
         <adapter controlType="System.Web.UI.WebControls.RadioButtonList" adapterType="Telerik.Cms.Web.UI.Adapters.RadioButtonListAdapter" />
       </controlAdapters>


    Regards,
    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. Ivan
    Ivan avatar
    51 posts
    Registered:
    22 Aug 2007
    27 Aug 2010
    Link to this post
    Hi Ivan,

    Thank you for the code snippet. I am in the process of implementing it but I have hit a roadblock.  I need access to the ICmsPage page object.  I could do this with the custom InternalPage but I am not sure how to get a handle in the FormAdapter.

    If I do a this.Page call it returns the ASP.sitefinity_cmsentrypoint_aspx.

    Thanks.
    -Ivan
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Aug 2010
    Link to this post
    Hello Ivan,

    Cast this.Page to CmsPageBase. This will give you access the the current page.

    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
  5. Ivan
    Ivan avatar
    51 posts
    Registered:
    22 Aug 2007
    30 Aug 2010
    Link to this post
    Thanks Ivan!  I have my custom code working in preview mode now.
Register for webinar
5 posts, 0 answered