Sharepoint 2007 multiple configurable web parts on same page

142 Views Asked by At

I have problem with developing webPart that is configurable and can be placed multiple times on one site.

Here is my actual code:

[XmlRoot(Namespace = "TestWebPart")]
public class TestWebPart : Microsoft.SharePoint.WebPartPages.WebPart
{
    public TestWebPart()
    {
        this.ExportMode = WebPartExportMode.All;
    }

    private string listName;

    // SharePoint setting with required attributes
    [Browsable(true),
     Category("List Config"),
     WebPartStorage(Storage.Shared),
     FriendlyName("List Name"),
     Description("Name of a list to get images")]
    public string ListName
    {
        get { return listName; }
        set { listName = value; }
    }

    protected override void Render(HtmlTextWriter writer)
    {
        writer.Write("test");
    }
}

With this code I can place this WebPart only once per site.

I have tried changing WebPartStorage to Personal and didn't helped.

When I remove [XmlRoot(Namespace = "TestWebPart")] from class it can be placed multiple times, but does not have configurable properties.

Do you know how to handle that?

2

There are 2 best solutions below

0
Yevgeniy.Chernobrivets On

Try following:

1) Remove [XmlRoot(Namespace = "TestWebPart")] line.

2) Inherit your web part from System.Web.UI.WebControls.WebParts.WebPart instead of Microsoft.SharePoint.WebPartPages.WebPart.

3) Use attributes below for web part property:

   WebBrowsable(true), 
   Personalizable(PersonalizationScope.Shared), 
   SPWebCategoryName("List Config"), 
   WebDisplayName("List Name"),
   WebDescription("Name of a list to get images")
0
Tomasz On

I have fixed this issue with creating .dwp file instead of .webpart file and deploying it.