SharePoint Events

  5/13/2013 - Conference: SharePoint Summit 2013
  5/21/2013 - Webcast: SharePoint 2013 and ECM: Content Migration and Storage
  5/22/2013 - Webcast: Managing CAD in SharePoint
  5/23/2013 - Webcast: SharePoint Document Automation and E-Forms for Financial Services
  5/24/2013 - Webcast: What's New in Search for SharePoint 2013

 SharePoint Videos

  Why SharePoint 2013
  SharePoint 2013 Launch
  SharePoint 2013 Migration and Governance
  SharePoint 2013 and Enterprise Content Management
  Top Benefits of SharePoint 2013
  What's New in Business Intelligence in Office and SharePoint 2013
  SharePoint and Office 2013 Integration
  SharePoint 2013 Infrastructure Preview
  SharePoint, Lync, and, Exchange in the Cloud with Office 365
  Advanced Reporting in SharePoint with Microsoft Power View

 Archives

Opening SharePoint Links in a new windowUse SHIFT+ENTER to open the menu (new window).
Mail Enabled Lists vs. The Missing Windows 2008 POP3/IMAP Server Use SHIFT+ENTER to open the menu (new window).
7 Tools for SharePoint DevelopersUse SHIFT+ENTER to open the menu (new window).
Public Facing Masterpage TechniquesUse SHIFT+ENTER to open the menu (new window).
How to Quickly Deploy and Activate a Timer Service to Your Site CollectionUse SHIFT+ENTER to open the menu (new window).
Custom SharePoint Master Page Feature with WSP BuilderUse SHIFT+ENTER to open the menu (new window).
Date Math with InfoPathUse SHIFT+ENTER to open the menu (new window).
Enterprise Search Tricks and Tips Part 1Use SHIFT+ENTER to open the menu (new window).
Populating Word Documents With SharePoint Data. Try The DIP!Use SHIFT+ENTER to open the menu (new window).
Programmatic Deep Dive into Blank SharePoint Lookup ColumnsUse SHIFT+ENTER to open the menu (new window).
1 - 10 Next
Workaround for People Picker Post back Bug in ASPX pages in SharePoint 2010

(a.k.a: why is this people picker breaking my form when I do more than one postback?!)

By: Philip Stathis

The People Picker is a great tool to present and validate data from SharePoint users and, indirectly, the Active Directory and is a valuable asset to any custom ASPX page.

The problem is, in all of its implementations across default SharePoint pages, the forms being used only appear on load and then get submitted. This process does only one post back. If you create a form with multiple people pickers like this one:

Workaround_for_People_Picker_Post_back_Bug_in_ASPX_pages_in_SharePoint_2010

The user needs to be able to navigate this form while having set all these values in the people pickers and the viewstate would ordinarily be enough to handle that.

This is not the case.

NOTE: this was part of the August 2011 CU for SharePoint 2010 as can be seen here.

So if installing this CU is not an option, or this technique is applicable to you, here’s my work round:

Add this variable to your aspx page:

private static Hashtable userKeys = new Hashtable();

 

Next hit your Page_load logic:

protected void Page_Load(object sender, EventArgs e)

{

userKeys.Clear();

      Session.Clear();

       FormLogic.RetainPeopleEditors(Page.Controls, Session.SessionID, userKeys, out userKeys);

}

 

The method being used, along with dependant code snippets can be presented below

 

internal static void RetainPeopleEditors(ControlCollection controls, string sessionID, Hashtable userKeys, out Hashtable output)

{

 

            ArrayList controlList = new ArrayList();

            AddControls(controls, controlList);

 

            foreach (PeopleEditor editor in controlList)

            {

                string key = editor.ID + sessionID;

                if (userKeys.ContainsKey(key))

                    userKeys[key] = RetainPeople(editor, (ArrayList)userKeys[key]);

                else

userKeys.Add(editor.ID + sessionID, RetainPeople(editor, (ArrayList)userKeys[editor.ID + sessionID]));

            }

 

            output = userKeys;

}

 

private static void AddControls(ControlCollection controlCollection, ArrayList controlList)

{

            foreach (Control c in controlCollection)

            {

                if (c.ID != null)

                {

                    if (c is PeopleEditor)

                        controlList.Add(c);

                }

 

                if (c.HasControls())

                {

                    AddControls(c.Controls, controlList);

                }

            }

}

private static ArrayList RetainPeople(PeopleEditor pe, ArrayList userKey)

{

            ArrayList peEntities = pe.ResolvedEntities;

            if (peEntities.Count > 0)

            {

                ArrayList entities = peEntities;

                return entities;

            }

            else if (userKey != null)

            {

                pe.UpdateEntities(userKey);

                pe.Validate();

                return userKey;

            }

            return null;

}

 

To provide an explanation of the method, you essentially create a HashTable that remains in the memory of the page, and append the keys with a session ID to ensure uniqueness when other people access your form.

As you may have noticed, the Picker Entity element cannot be stored in session since the class is not serializable.

This workaround will essentially stop the People Editor from having to grab values from the viewstate of the page. So this method is an assisted view state for people pickers.

Enjoy!

By: Philip Stathis

        

Comments

Pravin

Nice Post.!!!!!
at 1/9/2013 9:18 AM

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Your Name *


e-mail address *


Website (optional)


Comment *


Attachments

 Subscribe

  GigWerks RSS  Gig Werks Mailing List 

 Contact Us

 Connect

 Resources

  On Demand SharePoint Webcast Recordings
  Upcoming Webinars
  SharePoint Resources
  Business Intelligence Resources
  Gig Werks Website



©2009 Gig Werks. All rights reserved. Privacy Policy