Ejemplo n.º 1
0
        /// <summary>
        /// Implementation of IPostBackDataHandler.LoadPostData().
        /// This method examines the postback data and updates the control's state.
        /// </summary>
        /// <param name="postDataKey">Provides the dictionary key for the control instance.</param>
        /// <param name="postCollection">A dictionary collection of all incoming form values.</param>
        /// <returns>True if the control's state changes.</returns>
        /// <remarks>If this method returns true, the .NET framework will call RaisePostDataChangedEvent().
        ///
        /// Because this is effectively a composite control with the potential for multiple fields
        /// being returned, the postDataKey parameter is ignored.</remarks>
        public bool LoadPostData(string postDataKey, NameValueCollection postCollection)
        {
            selectAction action = GetSelectAction(postCollection);
            bool         StateHasChanged;

            if (action != selectAction.None)
            {
                StateHasChanged = ProcessSelectionAction(action, postCollection);
            }
            else
            {
                StateHasChanged = ProcessAsynchronousAction(postCollection);
            }

            return(StateHasChanged);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Helper function to process the select/remove operation and update the control's state.
        /// </summary>
        /// <param name="action">Specifies whether items are being selected or removed.</param>
        /// <param name="postData">A dictionary collection of all incoming form values.</param>
        /// <returns>True if the action results in a state change, false if no change has occured.</returns>
        /// <remarks>It is possible for this method to return false if the impact of a selection
        /// action is that no change has occured.  For example, if the user clicks the "Remove" button, but
        /// the only items selected are in the Additions list.</remarks>
        private bool ProcessSelectionAction(selectAction action, NameValueCollection postData)
        {
            bool selectionHasChanged = false;

            string[] selections = null;
            string   selectKey  =
                BuildUniqueControlName((action == selectAction.Select) ? _leftSelectName : _rightSelectName);

            if ((selections = postData.GetValues(selectKey)) != null)
            {
                foreach (ListItem item in Items)
                {
                    if (Array.Find(selections, delegate(string s) { return(s == item.Text); }) != null)
                    {
                        // Mark the item selected or unselected based on the current action.
                        item.Selected       = (action == selectAction.Select);
                        selectionHasChanged = true;
                    }
                }
            }

            return(selectionHasChanged);
        }