1

Here's my control's code behind:

<PartialCaching(60, Nothing, "UsrCtl_WebUserControl.CacheString", Nothing, True)> _
Partial Class UsrCtl_WebUserControl
 Inherits System.Web.UI.UserControl

 Private _CacheString As String

 Public Property CacheString() As String
  Get
   Return _CacheString
  End Get
  Set(ByVal value As String)
   _CacheString = value
  End Set
 End Property
End Class

Here's the Control's Markup:

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="WebUserControl.ascx.vb" Inherits="UsrCtl_WebUserControl" %>
<span>Control Generated <%=DateTime.Now%></span>

It just outputs the current time.

Here's the user control embedded in a page:

<uc:wuc ID="wuc" runat="server" CacheString="A" />

And in another page:

<uc:wuc ID="wuc" runat="server" CacheString="B" />

According to the docs this control should maintain a different, 60 second cached version for each value of the CacheString property.

It doesn't work - it caches for 60 seconds, but only one cached copy is created regardless of what I put in the CacheString property.

Anyone any ideas what i'm doing wrong? - After 4 hours of this I have no hair or nails left - please save my monitor from the brick.

4

1 回答 1

1

好的,我花了一点时间,但我只是复制了你的问题。当两个控件在多个页面中具有相同的 ID并且PartialCaching属性的构造函数中设置SharedTrue. 根据此处的文档,构造函数中的 Shared 属性是“true 表示用户控件输出可以与多个页面共享”,这意味着,如您所见,第一个加载的控件设置它,后续控件可以只阅读已经存在的内容。在幕后,控件似乎仅根据控件的 ID 进行缓存,而不考虑控件所在的页面。

因此,有两种可能的解决方案:

  • 更改页面上控件的ID
  • 在 PartialCaching 构造函数中,将 Shared 设置为 false。
于 2010-05-11T14:27:33.823 回答