1

I´m working on a webpart in SharePoint 2010. I´m loading some People Editor controls with usernames, but after postback they´r cleared. I´m now trying to fill them again, but it won't work. I can see when I debug it that the entities is there, but it´s not showing in the form. What´s wrong?

Ascx:

           <SharePoint:PeopleEditor ID="PeopleEditorProjectManagerNetGroup" runat="server" CssClass="ms-inputuserfield" Width="400" BorderStyle="Solid" BorderColor="Black" BorderWidth="1" MultiSelect="false" />
<asp:Button ID="buttonEdit" runat="server" Text="Redigera" 
            CssClass="ms-ButtonHeightWidth" onclick="buttonEdit_Click" />
        <asp:Button ID="ButtonOK" runat="server" Text="Spara" 
            CssClass="ms-ButtonHeightWidth" onclick="ButtonOK_Click" />
            &#160;
        <asp:Button ID="ButtonCancel" runat="server" Text="Avbryt" 
            CssClass="ms-ButtonHeightWidth" onclick="ButtonCancel_Click" />

Code behind (it´s when I hit the edit-button the values are gone):

 protected void Page_Load(object sender, EventArgs e)
    {         
        if (!Page.IsPostBack)
        {
            LoadProjectData();
            EditMode(false);
        }
    }
 protected void ButtonOK_Click(object sender, EventArgs e)
    {
        SaveProjectData();
        EditMode(false);
        LoadProjectData();            
    }

    protected void ButtonCancel_Click(object sender, EventArgs e)
    {
        EditMode(false);
    }

    protected void buttonEdit_Click(object sender, EventArgs e)
    {
        EditMode(true);
        LoadProjectData();

    }

    private void EditMode(bool isEditMode)
    {
        PeopleEditorProjectManagerNetGroup.Visible = isEditMode;
    }

     private void LoadProjectData()
    {

                    string projectManagerNetGroupLoginName = spWeb.GetProperty  (string.Format("DV_ProjectManagerNetGroup", SPContext.Current.Web.Name)).ToString();
                    PickerEntity entity = new PickerEntity();
                    entity.Key = projectManagerNetGroupLoginName;
                    entity = PeopleEditorProjectManagerNetGroup.ValidateEntity(entity);
                    PeopleEditorProjectManagerNetGroup.Entities.Add(entity);
                    labelProjectManagerNetGroup.Text = entity.DisplayText;
    }
  • Seems like SharePoint throughs an javascript error from entityeditor.js "null is null or not an object"... I think it has something to do with that error. – David Einebrant Aug 21 '13 at 7:25
0

I changed the LoadProjectData code slightly, and then it worked the first time I hit edit-button. But when I click cancel and then edit again, I got a javascript error (null is null or not an object), and the people editor was not filled with data.

I therefore redirect to current page on cancel and ok. It´s a work around, but it works now.

Here is the code:

protected void Page_Load(object sender, EventArgs e)
{         
    if (!Page.IsPostBack)
    {
        LoadProjectData();
        EditMode(false);
    }
}
protected void ButtonOK_Click(object sender, EventArgs e)
{
    SaveProjectData();
    //Fix for SharePoint javascript error
    Response.Redirect(SPContext.Current.Web.Url);    
}

protected void ButtonCancel_Click(object sender, EventArgs e)
{
     //Fix for SharePoint javascript error
     Response.Redirect(SPContext.Current.Web.Url);   
}

protected void buttonEdit_Click(object sender, EventArgs e)
{
    EditMode(true);
    LoadProjectData();

}

private void EditMode(bool isEditMode)
{
    PeopleEditorProjectManagerNetGroup.Visible = isEditMode;
    labelProjectManagerNetGroup.Visible = !isEditMode;
}

 private void LoadProjectData()
{

                string projectManagerNetGroupLoginName = spWeb.GetProperty  (string.Format("DV_ProjectManagerNetGroup", SPContext.Current.Web.Name)).ToString();
                PickerEntity entity = new PickerEntity();
                entity.Key = projectManagerNetGroupLoginName;
                entity = PeopleEditorProjectManagerNetGroup.ValidateEntity(entity);
                System.Collections.ArrayList entityArrayList = new System.Collections.ArrayList();
                entityArrayList.Add(entity);
                PeopleEditorProjectManagerNetGroup.UpdateEntities(entityArrayList);                    labelProjectManagerNetGroup.Text = entity.DisplayText;
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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