4

To customize the Web Part Tool Part, im following this tutorial :

http://blogs.microsoft.co.il/blogs/dudin/archive/2011/04/17/sharepoint-2010-how-to-customize-the-web-part-tool-part.aspx

when i use On WebPart "with custom Tool Part" its work fine but when i add a Second web part "with custom Tool Part" in the same page and try to edit th custom property i got :

"The operation could not be completed because the Web Part was deleted by another user or is invalid."

Update :

public int _PaginationSize = 5;

[WebBrowsable(false)]
[Personalizable(PersonalizationScope.Shared)]

public int PaginationSize
{
     get
     {
       return _PaginationSize;
     }
     set
     {
       _PaginationSize = value;
     }
}
class Editor : Microsoft.SharePoint.WebPartPages.ToolPart
    {
        private DropDownList list;
        private Label Name;

        protected override void CreateChildControls()
        {
            ListeGroupes webPart = (ListeGroupes)this.ParentToolPane.SelectedWebPart;
            if (WebPartToEdit == null)
                return;

            Name = new Label();
            Name.Text = "Nbr elements : ";
            Controls.Add(Name);

            list = new DropDownList();
            list.DataSource = new int[] { 1, 2, 3, 4, 5 };
            list.DataBind();
            this.Controls.Add(list);

            base.CreateChildControls();
        }

        public override void ApplyChanges()
        {
            ListeGroupes webPart = (ListeGroupes)this.ParentToolPane.SelectedWebPart;
            if (webPart != null)
                webPart.PaginationSize = int.Parse(list.SelectedItem.Value);
        }

        public override void SyncChanges()
        {
            ListeGroupes webPart = this.WebPartToEdit as ListeGroupes;

            if (webPart != null)
            {
                list.SelectedValue = webPart.PaginationSize.ToString();
            }
        }

        public Editor(string webPartID)
        {
            this.ID = "Editor" + webPartID;
        }
    }
1
  • Hi, no idea ?!! Commented May 19, 2011 at 10:50

3 Answers 3

4

You will need to add a ID to your ToolPart (EditorPart). For example:

public MyEditorPart(string webPartID)    
{
  this.ID = "MyEditorPart" + webPartID;  
}

http://www.tonstegeman.com/Blog/Lists/Posts/Post.aspx?List=70640fe5-28d9-464f-b1c9-91e07c8f7e47&ID=36

2
  • Thx i will try this ASAP. Commented May 18, 2011 at 13:19
  • See update still got error Commented May 18, 2011 at 13:57
0

I can't check whole article you followed but I reviewed code samples. At first, you need to use SyncChanges to get initial state for your Tool Part. Also I would mark your custom property as Personalisable, but not WebBrowsable (using Attributes). Update: can we see full ToolPart code? that "list" variable looks suspicious. Update2: at first, if you just want user to pick from a enum with drop down list, you can skip tool part at all: http://www.aidangarnish.net/blog/post/Web-part-custom-property-dropdown-list.aspx; at second, you are using inconsistent way to get a webpart: sometimes this.ParentToolPane.SelectedWebPart, sometimes this.WebPartToEdit. I would use 2nd one everywhere.

4
  • @ivan-padabed i will add SyncChanges and mark my custom property as Personalisable, there is nothing special in my custom code its a gridview that show data from a sharepoint list and i use the custom property to define number elements to show in my gridview (NB : i got the error when i add 2 webparts in the same page but if use just 1 webpart its work fine) Commented May 18, 2011 at 10:46
  • @ivan-padabed : ToolPart code add Commented May 18, 2011 at 14:50
  • @ivan-padabed : this.WebPartToEdit implemented (still got error), create custom properties work fin but i need to know what is the problem with the custom ToolPart. Commented May 20, 2011 at 17:16
  • @markov00 : unfortunately I can't test your code because I'm out of my dev env, but it looks good. It could be Content DB issue - could you please try adding your WPs on a brand new page? Commented May 24, 2011 at 15:21
0

Have you implemented the WebPart's CreateEditorParts method correctly, that's where you're supposed to set the ID

public override EditorPartCollection CreateEditorParts()
{
  var editorArray = new ArrayList();
  // set the editor part's id to the webpart's id + identifier (can be anything)
  var editorPart = new MyCoolEditorPart { ID = ID + "_editorPart1" }; 
  editorArray.Add(editorPart);
  var editorParts = new EditorPartCollection(editorArray);
  return editorParts;

}

1
  • Yes my editorPart look like your exemple with ID and + identifier Commented May 26, 2011 at 15:43

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.