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.

父控制項,如果無法符合這兩項條件,如果是延遲的建立子控制項,可以使用來載入檢視狀態IDIf 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.

適用於

另請參閱