Create SharePoint (2010) ToolPart usable for more than one WebPart
I am using the basic instructions ([here][1]) for creating a property driven by a custom ToolPart.

All is good, except for the part where, in order to access the webpart property within the ApplyChanges method I must cast the "this.ParentToolPane.SelectedWebPart" back to a concrete "SimpleWebPart" class. 

    public override void ApplyChanges()
    {
        SimpleWebPart wp1 = (SimpleWebPart)this.ParentToolPane.SelectedWebPart;
        			
    // Send the custom text to the Web Part.
        wp1.Text = Page.Request.Form[inputname];
    }

Doing this means that I must pair each toolpart with a specific webpart. Is there a better way?
I cannot create an interface as there is no way of specifying a property in one. 

I ineptly tried an passing an event/eventhandler during toolpart creation, but that did not update the webpart property when called.

I could create a base class for all the webparts that have a public "Text" property, but that is fugly.

I could also get desperate and crack open the this.ParentToolPane.SelectedWebPart reference with Reflection and call any properties named "Text" that way.

Either way, I am staring down the barrel of a fair bit of faffing around only to find out each option is a dead end.

Has anyone done this and can recommend the correct method for creating a reusable toolpart?


  [1]: http://msdn.microsoft.com/en-us/library/dd584178%28v=office.11%29.aspx


Create SharePoint (2010) ToolPart usable for more than one WebPart
===

I am using the basic instructions ([here][1]) for creating a property driven by a custom ToolPart.

All is good, except for the part where, in order to access the webpart property within the ApplyChanges method I must cast the "this.ParentToolPane.SelectedWebPart" back to a concrete "SimpleWebPart" class. 

    public override void ApplyChanges()
    {
        SimpleWebPart wp1 = (SimpleWebPart)this.ParentToolPane.SelectedWebPart;
        			
    // Send the custom text to the Web Part.
        wp1.Text = Page.Request.Form[inputname];
    }

Doing this means that I must pair each toolpart with a specific webpart. Is there a better way?
I cannot create an interface as there is no way of specifying a property in one. 

I ineptly tried an passing an event/eventhandler during toolpart creation, but that did not update the webpart property when called.

I could create a base class for all the webparts that have a public "Text" property, but that is fugly.

I could also get desperate and crack open the this.ParentToolPane.SelectedWebPart reference with Reflection and call any properties named "Text" that way.

Either way, I am staring down the barrel of a fair bit of faffing around only to find out each option is a dead end.

Has anyone done this and can recommend the correct method for creating a reusable toolpart?


  [1]: http://msdn.microsoft.com/en-us/library/dd584178%28v=office.11%29.aspx

