There are many development patterns available and one that I like is Model-View-Presenter (MVP). With the MVP pattern, there are different variations that you can use. For example, there’s a variant called Passive View and another called Supervising Controller.
They all follow the principals of MVP but have subtle differences. The Passive View pattern is geared towards projects that are looking for a maximum amount of unit test coverage, including testing of the user interface. For this pattern the majority of code in the View component is moved to the Presenter. The view here has practically no behaviour of its own. For this pattern, the View knows next to nothing about the Model and instead exposes simple properties for all the information it wants to display.
When creating a Visual WebPart, sometimes you want the main functionality to be contained within the user control and not the WebPart, so that, for example, you can use the WebPart on multiple pages, one where the WebPart is hosted and users can edit the properties and another where only the user control is loaded and no WebPart manager, or WebPart zones, are available to allow editing of the properties.
In the later case, the properties defined in the WebPart would either be set to default values or be retrieved from the query string.
Now, how to setup the user control to receive the WebPart’s property values when contained in a WebPart?
I’m in the process of writing a Charting WebPart for SharePoint 2010, specifically aimed at the standard version, which does not come with such a feature. Of course, it’s still usable within an enterprise environment if you were to find it useful.
To download the solution and installation script, follow this link.