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

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;
        }
    }
share|improve this question
    
Hi, no idea ?!! –  Mahmoud May 19 '11 at 10:50
add comment

3 Answers

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

share|improve this answer
    
Thx i will try this ASAP. –  Mahmoud May 18 '11 at 13:19
    
See update still got error –  Mahmoud May 18 '11 at 13:57
add comment

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.

share|improve this answer
    
@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) –  Mahmoud May 18 '11 at 10:46
    
@ivan-padabed : ToolPart code add –  Mahmoud May 18 '11 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. –  Mahmoud May 20 '11 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? –  Ivan Padabed May 24 '11 at 15:21
add comment

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;

}

share|improve this answer
    
Yes my editorPart look like your exemple with ID and + identifier –  Mahmoud May 26 '11 at 15:43
add comment

Your Answer

 
discard

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

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