Control.LoadViewStateByID Control.LoadViewStateByID Control.LoadViewStateByID Control.LoadViewStateByID Property

定义

获取一个值,该值指示控件是否通过 ID 而不是索引参与加载其视图状态。Gets a value indicating whether the control participates in loading its view state by ID instead of index.

protected:
 property bool LoadViewStateByID { bool get(); };
protected bool LoadViewStateByID { get; }
member this.LoadViewStateByID : bool
Protected ReadOnly Property LoadViewStateByID As Boolean

属性值

如果控件通过 ID 加载其视图状态,则为 true;否则为 falsetrue if the control loads its view state by ID; otherwise, false. 默认值为 falseThe default value is false.

注解

默认情况下,当父控件将视图状态加载到它创建的子控件中时,它会通过父控件的Controls集合中每个子控件的位置来执行此项。By default, when a parent control loads view state into child controls it creates, it does this by the position of each child control in the parent control's Controls collection. 最初应用视图状态时,可能尚未创建所有子控件。When view state is initially applied, all child controls might not have been created. 在这种情况下,将保存尚未创建的控件的视图状态,并在以后创建子控件时应用该视图状态。In this case, the view state for controls not yet created is saved, and applied when the child controls are created later.

若要让父控件将视图状态应用到其子控件,必须满足两个条件:For a parent control to apply view state to its child controls, two conditions must be met:

  • 在回发时,父控件必须按与上一个请求完全相同的顺序创建子控件,以便控件的顺序保持一致。On postback, the parent control must create the child controls in exactly the same order as the previous request so that the order of the controls remains consistent.

  • 回发之后,必须将创建的任何子控件添加到父控件的Controls集合的末尾。After postback, any child controls created must be added to the end of the parent control's Controls collection.

如果不满足这两个条件,例如创建子控件延迟,则父控件可以使用ID加载视图状态。If these two conditions cannot be met, as in the case of the delayed creation of a child control, the parent control can load view state by using ID. 若要将LoadViewStateByID属性设置true为,请ViewStateModeByIdAttribute使用父控件的元数据特性。To set the LoadViewStateByID property to true, use the ViewStateModeByIdAttribute metadata attribute for the parent control.

适用于

另请参阅