8

我有一个定义了以下缓存的页面:

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

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

4

1 回答 1

4

选项一

在您的页面上使用替换控件或 API。这使您可以缓存页面上的所有内容,但替换控件中包含的部分除外。

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

使用它的一个好方法是将您的控件实现为一个简单的服务器控件,它将 html 呈现为一个字符串,但在页面的上下文中这样做(即使用正确的客户端 ID)。Scott Guthrie 有一个很好的例子来说明这是如何工作的。顺便说一句,也可以很好地与 AJAX 调用配合使用......

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

摘自 Scott Gu 的文章...

    [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 调用),并且只有调用的渲染结果会在页面之间发生变化。

于 2010-07-23T13:36:55.130 回答