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?
Try following:
1) Remove
[XmlRoot(Namespace = "TestWebPart")]line.2) Inherit your web part from
System.Web.UI.WebControls.WebParts.WebPartinstead ofMicrosoft.SharePoint.WebPartPages.WebPart.3) Use attributes below for web part property: