Sharepoint Toolpart Values Not Being Retrieved

1.1k Views Asked by At

I am looking to add custom properties to a tool part. I've been able to add the textbox as desired. I've been able to enter values and display it in the webpart.

The problem is when I edit the webpart - the panel pops up but the control I added is not populated with the previously entered value. See below:

Why doesn't this work? :(

I have followed the instructions on this website exactly as written - neither myself nor a more experienced Sharepoint developer co-worker is able to figure out what's going on here.

We thought that overriding the SyncChanges() method would allow for this - It seems it doesn't, unless our implementation isn't correct?

    public override void SyncChanges()
    {
        DemoWebPart wp = (DemoWebPart)this.ParentToolPane.SelectedWebPart;
        urls.Text = wp.ListValue;
    }

We have also prefixed the urls property of the DemoWebPart.cs class with the following, to no avail:

    [Browsable(true), Category("Miscellaneous"),
    DefaultValue("Site Names"),
    WebPartStorage(Storage.Shared / Personal / None),
    FriendlyName("URLs"), Description("Text Property")]

(Having tried Storage.Shared, Storage.Personal, and Storage.None).

Any help you can provide would be greatly appreciated - thanks in advance!

3

There are 3 best solutions below

2
On

This is the code I generally use for such properties:

[Personalizable(PersonalizationScope.Shared)]
[WebBrowsable(true)]
[System.ComponentModel.Category("Custom")]
[WebDisplayName("DisplayNameGoesHere")]
[WebDescription("Type the description of this web property here.")]
public string MyProperty{ get; set; }

I've never had any problems with it.

0
On

Suggestion :

  1. Create a new WP
  2. and use this article http://snahta.blogspot.com/2009/11/webpart-custom-properties.html

I have used this 100s of times , please give it try , it will work.

Thanks Sandeep

0
On

Only use the following if Webpart personalization is enbaled in central admin:

Personalizable(PersonalizationScope.Shared)

If it is not, remove the Personalizable attribute completely. Do not put in false or none in it, delete that attribute and use this:

WebPartStorage(Storage.Shared)