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 物件。

屬性

範例

下列範例會 Cache 使用 屬性,將 Web 服務器控制項的 Label 屬性值儲存 TextCache 與使用者控制項 txtValue 應用程式相關聯的 物件中。 它會使用 Cache 屬性來執行此動作,將專案指派為 的 txtName.Text 索引鍵參數值。

重要

這個範例有一個可接受使用者輸入的文字方塊,這可能會造成安全性威脅。 根據預設,ASP.NET Web 網頁會驗證使用者輸入未包含指令碼或 HTML 項目。 如需詳細資訊,請參閱 Script Exploits Overview (指令碼攻擊概觀)。

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可讓您儲存資料以供稍後擷取,且會在應用程式之間共用。 您儲存的資料與目前頁面或使用者會話無關。 透過此屬性存取資料,以提升建立資料時的頁面或應用程式效能。 如需使用快取的詳細資訊,請參閱 快取應用程式資料

適用於

另請參閱