locked
Creating Custom ToolPart for Custom webpart and preserving its property.

    Question

  • hi,

    I have created custom toopart for selecting list.

    but the value of the selected list is not preserved

    on Edit Page-->Modify Shared webpart -->Webpart toolpane--> Selected value of list is lost??

    If some one has implemented list picker toolpart or have some idea , pls answer

    • Moved by Mike Walsh FIN Monday, June 21, 2010 4:53 PM questions on self-created web parts are programming not customization (From:SharePoint - Design and Customization (pre-SharePoint 2010))
    Monday, June 21, 2010 4:28 PM

Answers

  • When overridden in a derived class, this method is called after all other tool parts have called their ApplyChanges methods.

    The ToolPaneCalls the SyncChanges method for each tool part after all tool parts have successfully called the ApplyChanges method. A tool part should override the SyncChanges method with code to synchronize its user interface to the current values of any custom properties that affect its functionality, because other tool parts may have changed these values. If an error occurs when calling ApplyChanges, the ToolPane will not call SyncChanges for any tool parts

    Is something failing in ApplyChanges?

    Can you post more detailed code? it would help to diagnose the issue

    Also, refer the following links to understand the implementation of this method

    • Marked as answer by Wayne Fan Monday, July 12, 2010 10:13 AM
    Friday, June 25, 2010 6:11 PM

All replies

  • Hi Swati,

    The custom tool part will not preserve the values automatically, you need to provide the values to the toolpart

    To provide the properties to web part from toolpart use the ApplyChanges method of the Toolpart, where you fetch the values from the toolpart and assign it to web part properties

     

    public override void ApplyChanges() 
        { 
          WebPart1 wp = (WebPart1)this.ParentToolPane.SelectedWebPart; 
          wp.Property1 = ddl.SelectedValue; 
          wp.Property2 = tb.Text; 
        } 

     

    To display the values when you are editing the values use the SyncChanges method

     

    public override void SyncChanges() 
        { 
          WebPart1 wp = (WebPart1)this.ParentToolPane.SelectedWebPart; 
          ddl.SelectedValue = wp.Property1; 
          tb.Text = wp.Property2; 
        } 

     

    To persist the values in "Property1" and "Property2" so that you can set them in SyncChnages() method

    use WebPartStorage attributes for the properties you are trying to persist. If a WebPartStorage attribute is not specified for a property, Storage.PerUser is used by default

    [Browsable(true),Category("Miscellaneous"),
          DefaultValue(""),
          WebPartStorage(Storage.Personal),
          FriendlyName("Property1"),Description("Text Property")]
          publicstring Property1
          {
             get
             {
                return property1;
             }
     
             set
             {
                property1= value;
             }
          }

    --

    Dhiren (My Blog)

    ---------------------------------------

     

    Monday, June 21, 2010 6:06 PM
  • hi

    this sync method is not getting called

    on Edit Page -- >Modify webpart still values are getting lost

    _txtListUrl.Text = webPart.ListUrl;

    _txtTopCount.Text = webPart.TopCount.ToString();

     

    i set WebPartStorage(Storage.Personal),

    for all properties

    Friday, June 25, 2010 8:25 AM
  • When overridden in a derived class, this method is called after all other tool parts have called their ApplyChanges methods.

    The ToolPaneCalls the SyncChanges method for each tool part after all tool parts have successfully called the ApplyChanges method. A tool part should override the SyncChanges method with code to synchronize its user interface to the current values of any custom properties that affect its functionality, because other tool parts may have changed these values. If an error occurs when calling ApplyChanges, the ToolPane will not call SyncChanges for any tool parts

    Is something failing in ApplyChanges?

    Can you post more detailed code? it would help to diagnose the issue

    Also, refer the following links to understand the implementation of this method

    • Marked as answer by Wayne Fan Monday, July 12, 2010 10:13 AM
    Friday, June 25, 2010 6:11 PM
  • Hi,

     

    I have same problem.

    The value that i select exist for that instance but after saving the properties when i come back to edit mode the value is lost.

    If you have a working solution can u help me please?

     

    Thanks

    Monday, March 07, 2011 5:33 PM