关闭页面级别的缓存在用户控件 [英] Turn off page-level caching in a user control

查看:201
本文介绍了关闭页面级别的缓存在用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下定义的高速缓存的页面:

I have a page with the following caching defined:

<%@ OutputCache Duration="60" VaryByParam="None" %>

我有我不想缓存的页面中用户控件。我怎样才能关闭它只是为控制?

I have a user control inside that page that i don't want cached. How can I turn it off just for that control?

推荐答案

方案一

使用替换控制或你的页面上的API。这使您能够缓存的一切你的页面上除了包含替代控制范围内的部分。

Use the Substitution control or API on your page. this enables you to cache everything on your page except the part contained within the substitution control.

http://msdn.microsoft.com/en-us/library/ ms227429.aspx

使用这个是实现你的控制作为一个简单的服务器控制,呈现HTML作为一个字符串,但这样做在页面的上下文的一个很好的方式(即用正确的客户ID)。斯科特·格思里有一个非常好的如何工作的例子。可以很好的和AJAX的方式也呼吁...

One nice way to use this is to implement your control as a simple server control which renders the html as a string, but does so in the context of the page (that is with the correct Client IDs). Scott Guthrie has a really nice example of how this works. Works nicely with AJAX calls too by the way...

<一个href="http://weblogs.asp.net/scottgu/archive/2006/10/22/Tip_2F00_Trick_3A00_-Cool-UI-Templating-Technique-to-use-with-ASP.NET-AJAX-for-non_2D00_UpdatePanel-scenarios.aspx" rel="nofollow">http://weblogs.asp.net/scottgu/archive/2006/10/22/Tip_2F00_Trick_3A00_-Cool-UI-Templating-Technique-to-use-with-ASP.NET-AJAX-for-non_2D00_UpdatePanel-scenarios.aspx

从斯科特谷的文章摘译...

Excerpt from Scott Gu's article...

    [WebMethod]
    public string GetCustomersByCountry(string country)
    {
       CustomerCollection customers = DataContext.GetCustomersByCountry(country);

        if (customers.Count > 0)
            //RenderView returns the rendered HTML in the context of the callback
            return ViewManager.RenderView("customers.ascx", customers);
        else
            return ViewManager.RenderView("nocustomersfound.ascx");
    }

方案二

渲染通过在页面加载AJAX调用的动态控制。这样,您就可以放心地缓存整个页面(包括AJAX调用),它是在页面之间改变通话的唯一的呈现结果。

Render the dynamic control via an AJAX call on the page load. This way, you can safely cache the entire page (including the AJAX call) and it is only the rendered result of the call that changes between pages.

这篇关于关闭页面级别的缓存在用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆