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 属性。

适用于