UserControl.Cache 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
Cache获取与包含用户控件的应用程序关联的对象。
public:
property System::Web::Caching::Cache ^ Cache { System::Web::Caching::Cache ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Web.Caching.Cache Cache { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Cache : System.Web.Caching.Cache
Public ReadOnly Property Cache As Cache
属性值
要 Cache 在其中存储用户控件数据的对象。
- 属性
示例
以下示例使用该Cache属性将 Web 服务器控件的Label属性值存储在Text与用户控件txtValue的应用程序关联的对象中Cache。 它使用该 Cache 属性执行该操作,为项分配键参数值 txtName.Text。
重要
此示例有一个接受用户输入的文本框,这是潜在的安全威胁。 默认情况下,ASP.NET 网页验证用户输入是否不包含脚本或 HTML 元素。 有关详细信息,请参阅 脚本攻击概述。
private void cmdAdd_Click(Object objSender, EventArgs objArgs)
{
if (txtName.Text != "")
{
// Add this item to the cache.
Cache[txtName.Text] = txtValue.Text;
}
}
Private Sub cmdAdd_Click(objSender As Object, objArgs As EventArgs)
If txtName.Text <> "" Then
' Add this item to the cache.
Cache(txtName.Text) = txtValue.Text
End If
End Sub
注解
这样 Cache ,就可以存储数据以供以后检索,并在整个应用程序中共享。 存储的数据与当前页或用户会话无关。 如果创建数据速度缓慢,请通过此属性访问数据,以提高页面或应用程序性能。 有关使用缓存的详细信息,请参阅 缓存应用程序数据。