PageStatePersister.Load 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
當 Page 物件初始化其控制階層架構時,由衍生類別覆寫,以還原序列化並載入保存的狀態資訊。
public:
abstract void Load();
public abstract void Load ();
abstract member Load : unit -> unit
Public MustOverride Sub Load ()
範例
下列程式碼範例示範衍生自 類別的 PageStatePersister 類別如何實 Load 作 方法,以從持續性媒體載入檢視狀態。 嘗試 StreamPageStatePersister
從資料流程讀取資料。 它會使用 IStateFormatter 物件來還原序列化檢視狀態資料,並初始化 ViewState 屬性和 ControlState 屬性,該屬性是頁面用來初始化控制項。 此程式碼範例是針對 類別提供的較大範例的 PageStatePersister 一部分。
//
// Load ViewState and ControlState.
//
public override void Load()
{
Stream stateStream = GetSecureStream();
// Read the state string, using the StateFormatter.
StreamReader reader = new StreamReader(stateStream);
IStateFormatter formatter = this.StateFormatter;
string fileContents = reader.ReadToEnd();
// Deserilize returns the Pair object that is serialized in
// the Save method.
Pair statePair = (Pair)formatter.Deserialize(fileContents);
ViewState = statePair.First;
ControlState = statePair.Second;
reader.Close();
stateStream.Close();
}
'
' Load ViewState and ControlState.
'
Public Overrides Sub Load()
Dim stateStream As Stream
stateStream = GetSecureStream()
' Read the state string, using the StateFormatter.
Dim reader As New StreamReader(stateStream)
Dim serializedStatePair As String
serializedStatePair = reader.ReadToEnd
Dim statePair As Pair
Dim formatter As IStateFormatter
formatter = Me.StateFormatter
' Deserilize returns the Pair object that is serialized in
' the Save method.
statePair = CType(formatter.Deserialize(serializedStatePair), Pair)
ViewState = statePair.First
ControlState = statePair.Second
reader.Close()
stateStream.Close()
End Sub
備註
衍生自 類別的 PageStatePersister 類別會實作 方法, Load 以從某些持續性格式初始化 ViewState 和 ControlState 屬性。