In my previous article SharePoint WebPart Using Web User Control I explained how to crate web part with web user control (.ascx file). Working more with webparts and some silverlight web user control, I realised the need of generic webpart that accepts user control file name in webpart properties and you are all set.
This webpart you have to install just once and add on any page to show your user controls.
Note: in my next articles, I will explain how to use this webpart to plug silverlight controls.
For this webpart deployment I used codeplex sharepoint installer.
Please follow steps to install, configure and know how to use SPgenericWebPart.
1. Download the attached zip file with this article.
2. Click setup.exe
3. Click Next and it will check following items

4. Select your site from th list to deploy this webpart on.

5. Wait for installation being completed.

6. Add SPgeneric webpart to any webpart region.

7. Click to modify shared webpart properties.

8. Copy user control file name in 12/templates/layout/webusercontrol.ascx directory. You can create sub directory in ‘layout’. So it will look like 12/templates/layout/controls/webusercontrol.ascx
Now interwsting thing in this webpart is you can pass parameters to user control wrapped in it. And you can access it in page load event there. Which makes things lot of easier. !!
9. This web part has 3 properties configurable:
a. User control File name: specify user control file path in ‘layout/’ folder.
b. List Guid: GUID for any list that you want to read in web user control.
c. Extra property: extra property that you want to use for custome use.
Important: all these properties are passed to user control. You can also pass it to embbeded silverlight object. Hence it’s easy to create silverlight webpart using this approch.

10. Ultimately, you can see your user control in webpart.

Once you inatall this webpart you can see:
- SPGenericWebpart is added to your web part gallary
- SPGenericWebpart Feture is installed and activated in your site collaction fetures.
- One dll is added in your webapplications /bin folder.

Facts:
How to plug user control which uses custom library or other external references.
- Crate webapplication(not web site) and user control. Build it.
- Then add dll from webapplication’s “/bin” directory to “inetpub/wwwroot/wss/90/bin/” dir.
Installation of this webpart adds dll to bin directory and not to GAC
More than one webpart of this type can be added on same page. And webpart is inherited from webpart pages(FYI).
Configuration:
1. Configurable properties are:
a. User control File name: specify user control file path in ‘layout/’ folder.
b. List Guid: GUID for any list that you want to read in web user control.
c. Extra property: extra property that you want to use for custome use.
2. How to access parameters in user control (.ascx) code behind, may be page load
this.Attributes["ControlURL"].ToString();
this.Attributes["ListGUID"].ToString();
this.Attributes["Expr1"].ToString();
3. Web User Control related dll goes to wwwroot/wss/90/bin
That’s all! Check later articles for more on silverlight webpart in moss 2007 (if you are not planing to upgrade to 2010)
Thanks