I'm very new at Sharepoint and I faced to a trick issue.

Here is the situation : in an .aspx.cs file, I've created an EventHandler called btnValidate_Click, raised on a click on a button. In this EventHandler, I need to get values of some fields displayed on the page, in order to insert them in various lists.

In one of my list, I have a User column, and I would like to display it, get the value defined by the end-user, and insert it in my list.

Here is my code :

<asp:Repeater runat="server" ID="RepeaterWorkTeamUser" DataSourceID="SPDataSourceWorkTeam" EnableViewState="true">
            <%-- Headers --%>
                <asp:TextBox runat="server" ID="txtTitle" EnableViewState="true" />
                <%--Some others fields --%>
                <SharePoint:UserField runat="server" ID="spufManager" EnableViewState="true" ControlMode="Edit" Visible="true" />

In my btnValidate_Click EventHandler, this is how I get my values :

public void btnValidate_Click(object sender, EventArgs e)
        SPWeb web = SPContext.Current.Web;
        SPList listWorkers = web.Lists["WorkTeam"];

        foreach (RepeaterItem i in RepeaterWorkTeamUser.Items)
            SPListItem workTeamListItem = listWorkers.AddItem();

            TextBox txtNom = (TextBox)i.FindControl("txtName");
            workTeamListItem["Nom"] = txtNom.Text;

            <%-- Some others properties --%>

            SPFieldUserValue userValue = new SPFieldUserValue(web, web.CurrentUser.ID, web.CurrentUser.LoginName);
            workTeamListItem["Manager"] = userValue;


But the field "Manager" doesn't even appear on my page, whereas others fields are correctly displayed, and their values are correctly inserted on the list.

I tried with a

Can somebody help me to display it correctly, and get the chosen user in my EventHandler to add it to my list ?

Thanks in advance :-)


2 Answers 2


Please, try the following code:

SPUser user = web.EnsureUser("{user login}");
item["Manager"] = user;
  • I tried your sample, but I don't know the user login because the end-user has to type it... I replace your {"user login"} by userValue, definied as follow : SPFieldUserValue userValue = new SPFieldUserValue(web, ufResponsable.ItemId, ufResponsable.Value.ToString()); but it didn't work and my <SharePoint:FormField> still doesn't appear on my webpage... Any other idea ?
    – AlexB
    Commented May 3, 2013 at 7:16
  • What type is "ufResponsable"?
    – Andrew
    Commented May 3, 2013 at 8:22

I finally found a solution.

I'm still unable to display a , so I used a PeopleEditor as explained here : http://karinebosch.wordpress.com/sharepoint-controls/peopleeditor-control/

Then, in my aspx.cs file, here is how I get the selected user :

PeopleEditor peManager = (PeopleEditor)i.FindControl("peManager");
peResponsable.AutoPostBack = true;
PickerEntity pe = (PickerEntity)peManager.Entities[0];
workTeamListItem["Manager"] = pe.EntityData["SPUserID"];

Fix it !

Oh, by the way If you experience an issue with IE9, like "Namespace prefix 'xsd' is not defined" when submitting datas, follow this link and look like the M_Olson's answer : his solution perfectly works. http://social.msdn.microsoft.com/forums/en-US/sharepointgeneralprevious/thread/90b3835c-6754-4bb6-9fd4-b74f16f236ff I also use this other M_Olson's answer for this IE9 issue : http://*social.msdn.microsoft.com/forums/en-US/sharepointcustomizationprevious/thread/8457c2f7-70f7-4500-a71c-31b1cf2b22eb

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.