protected internal virtual void AddedControl (Control control, int index) { ResetControlsCache (); /* Ensure the control don't have more than 1 parent */ if (control._parent != null) control._parent.Controls.Remove (control); control._parent = this; Control nc = ((stateMask & IS_NAMING_CONTAINER) != 0) ? this : NamingContainer; if ((stateMask & (INITING | INITED)) != 0) { control.InitRecursive (nc); control.SetMask (REMOVED, false); } else { control.SetNamingContainer (nc); control.SetMask (REMOVED, false); return; } if ((stateMask & (VIEWSTATE_LOADED | LOADED)) != 0) { if (pendingVS != null) { object vs; bool byId = LoadViewStateByID; string id; if (byId) { control.EnsureID (); id = control.ID; vs = pendingVS [id]; } else { id = null; vs = pendingVS [index]; } if (vs != null) { if (byId) pendingVS.Remove (id); else pendingVS.Remove (index); if (pendingVS.Count == 0) pendingVS = null; control.LoadViewStateRecursive (vs); } } } if ((stateMask & LOADED) != 0) control.LoadRecursive (); if ((stateMask & PRERENDERED) != 0) control.PreRenderRecursiveInternal (); }
/// <devdoc> /// </devdoc> protected internal virtual void AddedControl(Control control, int index) { if (control.OwnerControl != null) { throw new InvalidOperationException(SR.GetString(SR.Substitution_NotAllowed)); } if (control._parent != null) { control._parent.Controls.Remove(control); } control._parent = this; control._page = Page; control.flags.Clear(designModeChecked); // We only add to naming container if it is available. Otherwise, it will be pushed through // during InitRecursive Control namingContainer = flags[isNamingContainer] ? this : _namingContainer; if (namingContainer != null) { control.UpdateNamingContainer(namingContainer); if (control._id == null && !control.flags[idNotRequired]) { // this will also dirty the name table in the naming container control.GenerateAutomaticID(); } else if (control._id != null || (control._controls != null)) { // If the control has and ID, or has children (which *may* themselves // have ID's), we need to dirty the name table (ASURT 100557) namingContainer.DirtyNameTable(); } } /* * The following is for times when AddChild is called after CreateChildControls. This * allows users to add children at any time in the creation process without having * to understand the underlying machinery. * Note that if page is null, it means we haven't been attached to a container ourselves. * If this is true, when we are, our children will be recursively set up. */ if (_controlState >= ControlState.ChildrenInitialized) { Debug.Assert(namingContainer != null); control.InitRecursive(namingContainer); // VSWhidbey 396372: We need to reregister the control state if the control is reparented because the control // is unregistered during unload, but its already been inited once, so it will not get its Init called again // which is where most controls call RegisterRequiresControlState if (control._controlState >= ControlState.Initialized && control.RareFields != null && control.RareFields.RequiredControlState) { Page.RegisterRequiresControlState(control); } if (_controlState >= ControlState.ViewStateLoaded) { object viewState = null; if(_occasionalFields != null && _occasionalFields.ControlsViewState != null) { viewState = _occasionalFields.ControlsViewState[index]; // This solution takes the conservative approach that once viewstate has been // applied to a child control, it is thrown away. This eliminates inadvertently // setting viewstate on the wrong control, which can occur in scenarios where // the child control collection is being manipulated via code. Probably need // to provide a feature where programmer can control whether to reapply viewstate // or not. if (LoadViewStateByID) { control.EnsureID(); viewState = _occasionalFields.ControlsViewState[control.ID]; _occasionalFields.ControlsViewState.Remove(control.ID); } else { viewState = _occasionalFields.ControlsViewState[index]; _occasionalFields.ControlsViewState.Remove(index); } } control.LoadViewStateRecursive(viewState); if (_controlState >= ControlState.Loaded) { control.LoadRecursive(); if (_controlState >= ControlState.PreRendered) control.PreRenderRecursiveInternal(); } } } }
protected internal virtual void AddedControl(Control control, int index) { if (control.OwnerControl != null) { throw new InvalidOperationException(System.Web.SR.GetString("Substitution_NotAllowed")); } if (control._parent != null) { control._parent.Controls.Remove(control); } control._parent = this; control._page = this.Page; control.flags.Clear(0x20000); Control namingContainer = this.flags[0x80] ? this : this._namingContainer; if (namingContainer != null) { control.UpdateNamingContainer(namingContainer); if ((control._id == null) && !control.flags[0x40]) { control.GenerateAutomaticID(); } else if ((control._id != null) || (control._controls != null)) { namingContainer.DirtyNameTable(); } } if (this._controlState >= System.Web.UI.ControlState.ChildrenInitialized) { control.InitRecursive(namingContainer); if (((control._controlState >= System.Web.UI.ControlState.Initialized) && (control.RareFields != null)) && control.RareFields.RequiredControlState) { this.Page.RegisterRequiresControlState(control); } if (this._controlState >= System.Web.UI.ControlState.ViewStateLoaded) { object savedState = null; if ((this._occasionalFields != null) && (this._occasionalFields.ControlsViewState != null)) { savedState = this._occasionalFields.ControlsViewState[index]; if (this.LoadViewStateByID) { control.EnsureID(); savedState = this._occasionalFields.ControlsViewState[control.ID]; this._occasionalFields.ControlsViewState.Remove(control.ID); } else { savedState = this._occasionalFields.ControlsViewState[index]; this._occasionalFields.ControlsViewState.Remove(index); } } control.LoadViewStateRecursive(savedState); if (this._controlState >= System.Web.UI.ControlState.Loaded) { control.LoadRecursive(); if (this._controlState >= System.Web.UI.ControlState.PreRendered) { control.PreRenderRecursiveInternal(); } } } } }