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.

備註

根據預設,當父控制項將 view 狀態載入它所建立的子控制項時,它會透過父控制項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. 一開始套用 view 狀態時,可能不會建立所有的子控制項。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使用父控制項的 metadata 屬性。To set the LoadViewStateByID property to true, use the ViewStateModeByIdAttribute metadata attribute for the parent control.

適用於

另請參閱