在Defalut.aspx里加上
<%@ OutputCache Duration="60" VaryByParam="none"%>进行缓存并且引入了一个自己的控件:
<%@ Register Src="best.ascx" TagName="best" TagPrefix="uc1" %>
现在,我希望这个控件里的内容不被缓存,但是不知道该怎么做。哪位XD能教偶我一下啊,小弟在这里先谢啦。据说Substitutoin可以做到的,但我不知道该怎么办,最好的成果也就做到有一个字符串不被缓存。

解决方案 »

  1.   

    可以做到,方法与页面没有区别,自已写上去.
    <%@ Control Language="C#" CodeFile="AdvancedSearch.ascx.cs" Inherits="AdvancedSearch_ascx" %>
    <%@ OutputCache  Duration="70" %>
    <%@ Register TagPrefix="uc1" TagName="LocationDropDown" Src="~/Controls/LocationDropDown.ascx" %>
    <%@ Register TagPrefix="uc1" TagName="CategoryDropDown" Src="~/Controls/CategoryDropDown.ascx" %>
        <legend>Category:</legend>
        <uc1:CategoryDropDown ID="CategoryDropDown" Runat="server" />
        <p>
        </p>
        <legend>Search Term:</legend><span>
        <asp:TextBox ID="SearchTermTextBox" Runat="server" CssClass="post_title"></asp:TextBox></span>
        <p>
        </p>
        <legend>Maximum Price:</legend>$ <span>
        <asp:TextBox ID="MaximumPriceTextBox" Runat="server" CssClass="post_dollars"></asp:TextBox></span>
        <p>
        </p>
        <legend>Location:</legend>
        <uc1:LocationDropDown ID="LocationDropDown" Runat="server" ShowAnyLocationChoice="True" />
        <p>
        </p>
        <legend>Date:</legend>
        <asp:DropDownList ID="DayRangeList" Runat="server" OnSelectedIndexChanged="DayRangeList_SelectedIndexChanged">
            <asp:ListItem Value="-1" Selected="True">any</asp:ListItem>
            <asp:ListItem Value="1">within last day</asp:ListItem>
            <asp:ListItem Value="2">within last 2 days</asp:ListItem>
            <asp:ListItem Value="7">within last 7 days</asp:ListItem>
            <asp:ListItem Value="30">within last month</asp:ListItem>
        </asp:DropDownList>
        <p>
        </p>
        <legend>Show:</legend>
        <asp:DropDownList ID="AdTypeList" Runat="server" OnSelectedIndexChanged="AdTypeList_SelectedIndexChanged">
            <asp:ListItem Value="0">All Types</asp:ListItem>
            <asp:ListItem Value="1">For Sale only</asp:ListItem>
            <asp:ListItem Value="2">Wanted only</asp:ListItem>
        </asp:DropDownList><p>
        </p>
        <asp:CheckBox ID="PhotoCheckBox" Runat="server" Text="with Photo(s)" /><br />
      

  2.   

    <%@ OutputCache Duration="60" VaryByParam="none"%>缓存是对页面内容进行缓存,你可以使用数据缓存的方式来缓存信息啊
      

  3.   

    To: lnwuyaowei(风可以追我) 
        这样子的话,用户组件也会被缓存70秒,我现在希望插在页面里的用户控件是实时更新的,而页面除了控件部分是缓存的啊。
      

  4.   

    To: MyLoginname:
    缓存很简单,我是想实现部分缓存。再解释一下:是整个页面除我的控件以外缓存,只有我的控件不被缓存,每次刷新,内容都会改变。
      

  5.   

    不好意思,理解错了.
    下面是答案:
    http://msdn2.microsoft.com/zh-CN/library/ms227429.aspx
      

  6.   

    注意到了有一个叫
    Response.WriteSubstitution的方法,参数可以是“a method, user control or object to substitution”,但是,这地方只要一写我的控件名称,就出现异常:
    cannot convert from 'ASP.best_ascx' to 'System.Web.HttpResponseSubstitutionCallback'
    参数类型出问题了,这个参数应该传什么啊?
      

  7.   


    对你需要缓存的控件,进行 fragment cache 。试试
      

  8.   

    To 达子:
        用Fragmnet cache只能缓存控件,而我想实现的是缓存后替换!!!
      

  9.   

    失望了,结帖了。还是去找书看吧。回家修行去了。感谢lnwuyaowei(风可以追我)。