共用方式為


PageStatePersister.Load 方法

定義

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 以從某些持續性格式初始化 ViewStateControlState 屬性。

適用於