Question

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!

Était-ce utile?

La solution

When I have done the same I have always set the values of the custom property controls inside the ToolPart's CreateChildControls method to the corresponding values of the properties in the WebPart.

protected override void CreateChildControls()
{
   (MyWebPart) wp = (MyWebPart) this.ParentToolPane.SelectedWebPart;

   TextBox t = new TextBox();
   t.Text = wp.CustomTextProperty; // Set value to the webpart property
   this.Controls.Add(t);
}

This seems to work fine.

Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top