开发者

ASP.NET UserControl Caching

开发者 https://www.devze.com 2023-01-03 18:41 出处:网络
This thing is driving me nuts. I have a UserControl that is called WebUserControl. I need to cache this control, so I put the following in the WebUserControl.ascx:

This thing is driving me nuts. I have a UserControl that is called WebUserControl.

I need to cache this control, so I put the following in the WebUserControl.ascx:

<%@ OutputCache Duration="240" VaryByParam="FeedName" %>

Then I have the Default.aspx file in which I have:

      <div class="divInnerLeft" id="L1" runat=开发者_开发问答"server">
            <uc1:WebUserControl FeedId="a1" ID="a1" runat="server" FeedName=""/>
       </div>
       <div class="divInnerMiddle" id="M1" runat="server">
            <uc1:WebUserControl FeedId="a3" ID="a3" runat="server" FeedName=""/>
       </div>

In the Page_Load event I set the FeedName property - according to the user preferences.

The problem is that after initially loading the page, the controls are generated OK. But then, in the Page_Load event they are not available again. So the a1 and a3 are null and I cannot set the FeedName for different user.

How to solve this?

Thanks!


You realise that VaryByParam creates a new entry in the OutputCache for each varying parmateter set in the HTTP GET / POST QueryString.

Setting the FeedName property on the user control reference is not going to vary the cache for the user control.

What exactly are you trying to achieve in regards to caching here?

I think what you're looking for is VaryByControl

0

精彩评论

暂无评论...
验证码 换一张
取 消