0

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!

splatto
  • 3,159
  • 6
  • 36
  • 69

3 Answers3

1

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)
andrewsi
  • 10,807
  • 132
  • 35
  • 51
Will
  • 11
  • 1
1

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.

Servy
  • 202,030
  • 26
  • 332
  • 449
  • Just tried this...now it no longer saves what I type into the textbox to display in the webpart... – splatto Jan 24 '12 at 15:50
  • Temporarily clear out all of the stuff that you've posted in the OP to make sure they're not conflicting with each other. (The sync changes in particular.) – Servy Jan 24 '12 at 16:04
0

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

Sandeep
  • 436
  • 2
  • 5