Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

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)
        {
        }
    }

enter image description here

share|improve this question
    
I've tested your Editorpart code (with a non visual) web part in a sandboxed solution and it works fine. –  Per Jakobsen Oct 11 '12 at 9:10
    
have to made any changes in the code? Can you please send me the sample? email id Sharmila.k88@gmail.com –  sharmila Oct 11 '12 at 9:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.