0
votes

Developing a webpart in SharePoint 2013 and am having an issue with custom properties. The custom properties input boxes show up and all appears normal on the frontend. However, when I put a value in either box and hit 'Apply' the values coming into the setter are null.

Here is the ascx.cs file. GetEvents and GetNews are calls to other classes. They use the string coming in from the custom properties and pass them to the function to pull the custom lists. (They pull when I hard code the lists properly) Commented out are the default values because they seemed to work but then would not change because of the aforementioned issue with the setter.

    using System;
    using System.ComponentModel;
    using System.Web.UI.WebControls.WebParts;
    using System.Collections.Generic;
    using System.Collections;
    using System.Web.UI.WebControls;
    using System.Web.UI;

    namespace ListGet.VisualWebPart1
    {
        [ToolboxItemAttribute(false)]
        public partial class VisualWebPart1 : WebPart
        {
        //const string _eventDefaultList = "Events";
        //const string _newsDefaultList = "News";
        private string _eventsList;
        private string _newsList;

        [WebDisplayName("EventsList")]
        [WebDescription("Name of Events List")]
        [WebBrowsable(true)]
        [Personalizable(PersonalizationScope.Shared)]
        //[DefaultValue(_eventDefaultList)]
        public string EventsList
        {
            get { return _eventsList; }
            set { _eventsList = value; }
        }

        [WebDisplayName("NewsList")]
        [WebDescription("Name of News List")]
        [WebBrowsable(true)]
        [Personalizable(PersonalizationScope.Shared)]
        //[DefaultValue("News")]
        public string NewsList
        {
            get { return this._newsList; }
            set { this._newsList = value; }
        }

    public VisualWebPart1()
    {
    }

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        InitializeControl();
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected List<CalendarItem> GetEventItems()
    {
        EventsList events = new EventsList();
        return events.GetEvents(this.EventsList);
    }

    protected List<CalendarItem> GetNewsItems()
    {
        NewsList news = new NewsList();
        return news.GetNews(this.NewsList);
    }
}

}

1
After banging my head against a wall for a few hours, I figured it out. (Actually a co-worker pointed it out to me)Joe

1 Answers

0
votes

After several hours of beating my head against my desk, my co-worker looked at it and noticed that it was set as a sandbox solution. Let this be a lesson to everyone, check that first.