System.Web.UI.Control.LoadViewStateRecursive C# (CSharp) Method

LoadViewStateRecursive() private method

private LoadViewStateRecursive ( object savedState ) : void
savedState object
return void
		internal void LoadViewStateRecursive (object savedState)
		{
			if (savedState == null)
				return;

#if MONO_TRACE
			TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
			string type_name = null;
			if (trace != null) {
				type_name = GetType ().Name;
				trace.Write ("control", String.Concat ("LoadViewStateRecursive ", _userId, " ", type_name));
			}
#endif
			Pair savedInfo = (Pair) savedState;
			object[] controlAndAdapterViewStates = (object [])savedInfo.First;
			if (Adapter != null)
				Adapter.LoadAdapterViewState (controlAndAdapterViewStates [1]);
			LoadViewState (controlAndAdapterViewStates [0]);

			ArrayList controlStates = savedInfo.Second as ArrayList;
			if (controlStates == null)
				return;

			int nControls = controlStates.Count;
			bool byId = LoadViewStateByID;
			for (int i = 0; i < nControls; i++) {
				Pair p = controlStates [i] as Pair;
				if (p == null)
					continue;

				if (byId) {
					string id = (string)p.First;
					bool found = false;
					
					foreach (Control c in Controls) {
						c.EnsureID ();
						if (c.ID == id) {
							found = true;
							c.LoadViewStateRecursive (p.Second);
							break;
						}
					}

					if (!found) {
						if (pendingVS == null)
							pendingVS = new Hashtable ();
						pendingVS [id] = p.Second;
					}
				} else {
					int k = (int) p.First;
					if (k < Controls.Count) {
						Control c = Controls [k];
						c.LoadViewStateRecursive (p.Second);
					} else {
						if (pendingVS == null)
							pendingVS = new Hashtable ();

						pendingVS [k] = p.Second;
					}
				}
			}

#if MONO_TRACE
			if (trace != null)
				trace.Write ("control", String.Concat ("End LoadViewStateRecursive ", _userId, " ", type_name));
#endif
			stateMask |= VIEWSTATE_LOADED;
		}

Usage Example

Example #1
0
        /// <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();
                    }
                }
            }
        }
All Usage Examples Of System.Web.UI.Control::LoadViewStateRecursive