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

Forums / Developing with Sitefinity / Cache Substitution Controls

Cache Substitution Controls

16 posts, 0 answered
  1. Shane
    Shane avatar
    28 posts
    Registered:
    27 Jul 2008
    18 Mar 2009
    Link to this post

    Hi guys,

    I have just upgraded our site to 3.6 - and I am interested in the cache article you released yesterday.

    See:


    Can some one read my comment and tell me how to implement this model in a clustered environment. I want to flush the cache on each server?

    I have been waiting for type of functionality (out of the box) for a while. We want to cache pages except for things like a shopping basket etc.

    Can it be done?

    Thanks,

    Shane.
  2. Shane
    Shane avatar
    28 posts
    Registered:
    27 Jul 2008
    18 Mar 2009
    Link to this post
    I have found another issue.

    When I use the CacheSubstitutionUserControl to exclude a control from being cached I get the following error - it appears that if your control that is being excluded is using ajax it doesn't work:

    The control with ID 'EnquiryPanel' requires aScriptManager on the page. The ScriptManager must appear before anycontrols that need it.

    Description: Anunhandled exception occurred during the execution of the current webrequest. Please review the stack trace for more information about theerror and where it originated in the code.

    Exception Details: System.InvalidOperationException:The control with ID 'EnquiryPanel' requires a ScriptManager on thepage. The ScriptManager must appear before any controls that need it.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [InvalidOperationException: The control with ID 'EnquiryPanel' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it.]   System.Web.UI.UpdatePanel.get_ScriptManager() +363997   System.Web.UI.UpdatePanel.RegisterPanel() +87   System.Web.UI.UpdatePanel.OnInit(EventArgs e) +19   System.Web.UI.Control.InitRecursive(Control namingContainer) +333   System.Web.UI.Control.InitRecursive(Control namingContainer) +210   System.Web.UI.Control.InitRecursive(Control namingContainer) +210   System.Web.UI.Control.InitRecursive(Control namingContainer) +210   System.Web.UI.Control.InitRecursive(Control namingContainer) +210   System.Web.UI.Control.InitRecursive(Control namingContainer) +210   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +378
  3. Vlad
    Vlad avatar
    498 posts
    Registered:
    19 Jun 2017
    18 Mar 2009
    Link to this post
    Hello Shane,

    I answered your comment in:

    Please let us know if you have additional questions.

    As to the Ajax-related error you are getting, make sure that the PageMode of your substitution control is set to SubstitutionPageMode.Full. Actually, we had such problem with the Ajax substitutions controls in version 3.5, but it was fixed in v3.6.

    If, after making the above suggestion, you are still getting this error, could you please send us your substitution user control, so we could investigate it locally?

    All the best,
    Vlad
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  4. Shane
    Shane avatar
    28 posts
    Registered:
    27 Jul 2008
    18 Mar 2009
    Link to this post
    Thanks so much for you reply,

    I will look at what you have suggested today.

    I do have one question in reqards to using the aspnet cache provider in a web farm. I want to have the cache dropped on all servers if a page is deleted or published? That is why I wanted to use the InDatabase method?

    Is there a why to do this using the aspnet provider (dependancies?).

    Thanks,

    Shane
  5. Shane
    Shane avatar
    28 posts
    Registered:
    27 Jul 2008
    18 Mar 2009
    Link to this post
    Hi Vlad,

    I have done what you have suggested but I am still getting the same exception when I request the page for the second time. It cannot find the relevant script manager for the cached page.

    Here is my code:

    <%@ Control Language="C#" AutoEventWireup="false" CodeFile="TestControl.ascx.cs" Inherits="Controls_TestControl" %> 
    <asp:UpdatePanel ID="TimePanel" runat="server"
        <ContentTemplate> 
            <asp:Label ID="time" runat="server" ></asp:Label> 
            <asp:Button ID="GetTimeButton" runat="server" Text="Get Server Time"  
                onclick="GetTimeButton_Click" /> 
        </ContentTemplate> 
    </asp:UpdatePanel> 
     
     

    using System; 
    using Telerik.Cms.Web.UI; 
     
    public partial class Controls_TestControl : CacheSubstitutionUserControl 
        protected override void OnLoad(EventArgs e) 
        { 
            if (!IsPostBack) time.Text = GetTime(); 
            base.OnLoad(e); 
        } 
     
        protected void GetTimeButton_Click(object sender, EventArgs e) 
        { 
            time.Text = GetTime(); 
        } 
     
        private static string GetTime() 
        { 
            return string.Format("<h2>Time Requested: {0}</h2>", DateTime.Now.ToLongTimeString()); 
        } 
     
        public override SubstitutionPageMode PageMode 
        { 
            get 
            { 
                return SubstitutionPageMode.Full; 
            } 
        } 

    I hope you can see something I am doing wrong? If we can't implement the standard .Net ajax controls  in our user controls we are in trouble as we also want to enable caching on our pages.

    Secondly, you suggestion in your comment doesn't work as expected it seems when I set our base user controls PageMode to None things stop working (I get a Service Unavaliable error) unless I implement the SubstitutionCallback method.

    I really want a way to implement a clean way of implementing your CacheSubstitutionUserControl and implement our base functionality - and in addition, provide a suite of controls that are cached along with the page (if cached).

    Thanks,
    Shane,
  6. Vlad
    Vlad avatar
    498 posts
    Registered:
    19 Jun 2017
    19 Mar 2009
    Link to this post
    Hi Shane,

    Thank you for the code example.

    Regarding your question about Web Farm environment. Using the aspnet cache provider means that the page output will be stored in the memory. This has nothing to do with the cache dependency. In a load balanced environment, if you want changes made on one server to take effect to the others, you should set the cacheDependency mode to InDatabase in the web.config:

    <telerik> 
        ... 
        <framework> 
            <caching defaultProvider="memoryCache"
                <cacheDependency mode="InDatabase"/> 
            </caching> 
     


    As for the example,  the user control throws an exception. Actually, the ScriptManager is on the page, but it is loaded just after the control, which is the reason for the exception. We fixed the problem for the upcoming release, however it will be complicated to provided a workaround with the current release.
    Alternatively, it works fine with the RadAjaxPanel. However, there is another problem there, the work around for which is described in this forum.
    We apologize for the omissions. Your telerik points were updated for pointing us the problem with UpdatePanel.

    For the last issue, with the common user control, which inherits from CacheSubstitutionUserControl,  unfortunately we cannot reproduce and understand it. Seems this error is not thrown by our application. We have no idea how it can be related to this scenario. Can you give us more details? Or, is it possible for you to provide a code example again?

    Greetings,
    Vlad
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. Mike
    Mike avatar
    221 posts
    Registered:
    19 Aug 2008
    20 Mar 2009
    Link to this post
    Hi Vlad,

    I am receiving the same script manager error. You wrote the following:

    Actually, the ScriptManager is on the page, but it is loaded just after the control, which is the reason for the exception. We fixed the problem for the upcoming release, however it will be complicated to provided a workaround with the current release.

    What upcoming release is this exactly? And is there any way to provide a workaround for this in the mean time... My Site uses AJAX and the pre packaged RadControl that come with Sitefinity heavily. This error renders them useless for CacheSubstitution.

    Thanks,

    Duncan
  8. Vlad
    Vlad avatar
    498 posts
    Registered:
    19 Jun 2017
    22 Mar 2009
    Link to this post

    Hello Duncan,

    Most of the last found issues, like this one, will be addressed in the SP. We will try to release it at the beginning of the next month. We would like to integrate Q1 of RadControls for ASP.NET AJAX. Regarding the error, the fix in our code is very simple, however, providing a work around for it in the current release is much more complicated. I am not sure if it is worth, since the SP will be released very soon.
    Actually, as a workaround the RadAjaxPanel could be used instead of the asp.net UpdatePanel, because it works fine in the cache substitution controls.
    Please, let us know if you need a workaround with the UpdatePanel for the current version.


    Best wishes,

    Vlad
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  9. Shane
    Shane avatar
    28 posts
    Registered:
    27 Jul 2008
    26 Mar 2009
    Link to this post
    Hi,

    I posted a question in your blog:


    I don't think my question correctly. I have common functionality I require in two types of controls - one that will be cached and the other that is not cached (shopping basket etc).

    You mentioned that all I need to do is set the PageMode to None. That doesn't work as it is at some level not cached. I have controls that only display lists etc - they can be cached. Others are applications within our site. They require the pagemode to be set to Full.

    I am now stuck. I have to implement two base user controls one for no cache and another for caching controls. This means I have to repeat code in both - not good.

    If I set the base control PageMode to None it still expects the SubstitutionCallBack to be set. So in this case I set the callback to just return an empty string. This caused the control to not render anything.

    Is there anything I can do. Please let me know if this rant makes any sense.

    Thanks,

    Shane.
  10. Vlad
    Vlad avatar
    498 posts
    Registered:
    19 Jun 2017
    26 Mar 2009
    Link to this post
    Hi Shane,

    We investigated this problem further and it seems you are right - in the described scenario, when the PageMode is SubstitutionPageMode.None and SubstitutionCallback is null, the application crashes with StackOverflowException because the control Render method is used as a default callback and application goes to infinity loop. We reproduced the error and we will fix it for the service pack.

    Also, my answer in the blog regarding the SubstitutionPageMode.None was incorrect. Seems it does not disable the substitution behavior of the control. Sorry for giving you an incorrect information. We will include an option to completely disable the substitution in the upcoming release.

    In the meantime, you can use the following workaround. Override the Render method in your base common control:
        protected override void Render(System.Web.UI.HtmlTextWriter writer) 
        { 
            if (PageMode == SubstitutionPageMode.None && SubstitutionCallback == null
            { 
                this.RenderChildren(writer); 
            } 
            else 
            { 
                base.Render(writer); 
            } 
        } 

    In the next release, you should replace it with something like:
        public override bool SubstitutionEnabled 
        { 
            get 
            { 
                return false
            } 
        }  

    Sorry for the inconvenience.
    We updated your Telerik points for your efforts on resolving these issues.

    Sincerely yours,
    Vlad
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  11. Shane
    Shane avatar
    28 posts
    Registered:
    27 Jul 2008
    26 Mar 2009
    Link to this post

    Thank you for your help.

    This works as expected. There is of course testing to be done, but this is definalety a step in the right direction.

    Cheers,

    Shane
  12. Shane
    Shane avatar
    28 posts
    Registered:
    27 Jul 2008
    26 Mar 2009
    Link to this post

    Hi Vlad,

    I'm sorry but I have found another issue.

    Some of our usercontrols are using the standard asp.net ajax update panels. I know there are known issues in using your substitution base user control and scriptmanagers.

    I was told to use your radajaxpanel instead. This does work (mostly), however, when the page is first requested I get a dialog with a javascript error. See below:

    ---------------------------
    Error
    ---------------------------
    A Runtime Error has occurred.
    Do you wish to Debug?

    Line: 2710
    Error: Sys.ArgumentException: Value must not be null for Controls and Behaviors.
    Parameter name: element

    After the intial page request the page makes ajax requests with out any errors?

    Here is my user control and the javascript that is erroring out- I hope that helps.

    Javascript:

    // Name:        MicrosoftAjax.debug.js
    // Assembly:    System.Web.Extensions
    // Version:     3.5.0.0
    // FileVersion: 3.5.30729.1

    It appears the exception is being thrown?

    if (type.inheritsFrom(Sys.UI.Behavior) || type.inheritsFrom(Sys.UI.Control)) { 
            if (!element) throw Error.argument('element', Sys.Res.createNoDom); 
        } 

    UserControl:

    <%@ Control Language="C#" AutoEventWireup="false" CodeFile="TestControl.ascx.cs" Inherits="Controls_TestControl" %> 
     
    <telerik:RadAjaxPanel ID="AjaxPanel" runat="server"
        <asp:Label ID="time" runat="server"></asp:Label> 
        <asp:Button ID="GetTimeButton" runat="server" Text="Get Server Time" /><br /> 
    </telerik:RadAjaxPanel> 

    using System; 
    using Telerik.Cms.Web.UI; 
    using NZPost.Ecf.BusinessLayer.Controls.WebControls; 
     
    public partial class Controls_TestControl : ControlBase 
        protected override void OnLoad(EventArgs e) 
        { 
            time.Text = GetTime(); 
            base.OnLoad(e); 
        } 
     
        private static string GetTime() 
        { 
            return string.Format("<br/><br/><h2>Time Requested: {0}</h2><br/><br/>", DateTime.Now.ToLongTimeString()); 
        } 
     
        public override SubstitutionPageMode PageMode 
        { 
            get 
            { 
                return SubstitutionPageMode.Full; 
            } 
        } 
     
        protected override bool HasValidSettings() 
        { 
            return true
        } 

    Can you help?

    Cheers,

    Shane
  13. Shane
    Shane avatar
    28 posts
    Registered:
    27 Jul 2008
    26 Mar 2009
    Link to this post
    Hello again,

    I have done some further investigation using cached user controls.

    Scenaro:

    - I have cached a page (Enabled Page Cache).
    - I have placed a user control that displays a list of products. Its PageMode is set to None. Each product listed has an add to shopping cart button.

    The situation is this. Each time I hit one of the buttons in the list it seems that the whole page is executed again. I noticed this because my breakpoints where being hit in our custom navigation controls - they shouldn't have been hit again for one hour.

    In addition, the control with the list of products has code execute each time I hit an add to shopping cart button.

    I would have expected no code to run again, or at least on run once for each button on the page. I would have expected each button to create another cached page. This is how the standard asp.net output cache works.

    I would like if this is by design or a known issue?

    Thanks again,

    Shane
  14. Vlad
    Vlad avatar
    498 posts
    Registered:
    19 Jun 2017
    30 Mar 2009
    Link to this post
    Hello Shane,

    As for the first issue with the javascript error, we are currently investigating the problem and will let you know as soon we have a result.

    About the second issue:
    As far as I understand, your buttons do postback requests, right? I think this is the only reason, which can make a cached page to be executed again. The cached output is returned only for GET requests. This is the way the standard ASP.NET cache works. Actually, Sitefinity uses the standard ASP.NET caching by default, we just set it programmatically, depending on the cms page settings.
    Please let me know if I am missing something.

    Best wishes,
    Vlad
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  15. sam
    sam avatar
    102 posts
    Registered:
    31 Jan 2008
    31 May 2009
    Link to this post
    has this issue been resolved?
  16. Vlad
    Vlad avatar
    498 posts
    Registered:
    19 Jun 2017
    02 Jun 2009
    Link to this post
    Hello sam,

    Unfortunately, the problem with the RadAjaxPanel is not fixed yet. Actually, the fix requires some additional changes in the RadAjaxPanel implementation, which will be done in the next release of the RadControls. After that, we will release the next service pack of the Sitefinity v3.6, which will support cache substitution controls for almost all RadControls.

    We are sorry for the inconvenience.

    Greetings,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
16 posts, 0 answered