Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 25064

Custom EditorPart in Sharepoint Sandboxed solution.

$
0
0

Hi,

I want to implement the custom EditorPart in SharePoint sandboxed solution. I have the code like below. When I deploy the solution I cannot see the textbox and I noticed that the code is not executing. No controls are added in the toolpane . Can anyone tell me what I am missing or where have I gone wrong? I have used visualwebpart(sandboxed).

Note: I have found that the same code works fine when i work with the non visual webpart. but have no idea why it does not work with sandbxed visual webpart. Any help is appreciated.

public class CustomProperty : EditorPart
    {
        TextBox _tbTaskList;
        public CustomProperty()
        {
            Title = "Custom WebPart Settings";
        }

        public override bool ApplyChanges()
        {
            CustomWebPart part = (CustomWebPart)WebPartToEdit;
            //Update the custom WebPart control with the task list
            part.taskList = tbTaskList.Text;
            return true;
        }

        public override void SyncChanges()
        {
            CustomWebPart part = (CustomWebPart)WebPartToEdit;
            String currentList = part.taskList;
        }

        protected override void CreateChildControls()
        {
            Controls.Clear();

            //Add a new textbox control to set the task list
            _tbTaskList = new TextBox();

            Controls.Add(_tbTaskList);
        }

        protected override void RenderContents(HtmlTextWriter writer)
        {
            writer.Write("List Name :");
            writer.WriteBreak();
            _tbTaskList.RenderControl(writer);
            writer.WriteBreak();
        }

        private TextBox tbTaskList
        {
            get
            {
                EnsureChildControls();
                return _tbTaskList;
            }
        }
    }

CustomWebPart is the webpart name. the webpart class conatins:

public class CustomWebPart: System.Web.UI.WebControls.WebParts.WebPart
    {
       public override object WebBrowsableObject
       {
           get
           {
               return this;
           }
       }

       private String _taskList = null;

       [Personalizable(), WebBrowsable()]
       public String taskList
       {
           get { return _taskList; }
           set { _taskList = value; }
       }

       public override EditorPartCollection CreateEditorParts()
       {

           ArrayList editorArray = new ArrayList();
           CustomProperty edPart = new CustomProperty();
           edPart.ID = this.ID + "_editorPart1";
           editorArray.Add(edPart);
           EditorPartCollection editorParts = new EditorPartCollection(editorArray);
           return editorParts;
       }
    }

And my VisualWebaprt(sandboxed) class file contains:

[ToolboxItem(false)]
    public partial class VisualWebPart1 : System.Web.UI.WebControls.WebParts.WebPart
    {
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            InitializeControl();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
        }
    }







Viewing all articles
Browse latest Browse all 25064

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>