共用方式為


UserControl.Cache 屬性

定義

取得 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來將網頁伺服器控制項txtValue的屬性值Label儲存TextCache與使用者控制項應用程式相關聯的物件中。 它使用 屬性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 允許你儲存資料以便日後取得,並且會在整個應用程式中共享。 你儲存的資料與目前的頁面或使用者會話無關。 若資料建立緩慢,則透過此屬性存取資料以提升頁面或應用程式效能。 欲了解更多使用快取的資訊,請參閱快 取應用程式資料

適用於

另請參閱