March 24, 2004

SharePoint User Control Web Parts

Download Web Part User Control Loader
Here is the line you will need to add to your web.config to get this Web Part registered as safe:
<SafeControl Assembly="AnyControl, Version=1.0.0.1, Culture=Neutral, PublicKeyToken=72a8e2097fd71d02" Namespace="AnyControl" TypeName="*" Safe="True" />

Web references that mention using User Controls for Web Parts:

I have recently changed my ways and am now almost entirely using User Controls to power the Web Parts that I build.  What I've done for you today is build a Web Part that will auto detect any ASCX files in the SPS 2003 portal root and in the tool pane provide the user with a drop down box to choose which User Control to load.

I see it as specifically being a powerful tool in my testing and developing of new Web Parts.  The nice thing about it is that you don't have to include the User Controls into the same assembly as the Web Part I have built; make sure that the Web Part User Control Loader is being properly placed on your page, drop the ASCX files in the root directory of your portal, drop the DLL for your ASCX controls in the bin folder in the root directory of your portal, use the Web Part User Control Loader to load the User Controls you just placed.  No need to mark you User Control assemblies as safe in the web.config or to create a DWP file.

Some ideas for extending what I have done so far:

  • Use reflection to autodetect the public properties/methods of the loaded User Control, then building an interface for the user to modify the detected properties.
  • Fix the bug where after selecting a User Control you have to reload the page to get it to display the new control, there is an issue with when it updates the property of the Web Part and when the CreateChildControls() function in the Web Part runs :)
  • Fix up the ToolPart so that you can browse for User Control using a sexier interface

If you find this Web Part useful I would like it if you let me know and provide me with a copy of any modifications done.  I'm always interested in seeing how others interpret the possibilities of a piece of code.

Screenshots:
Initial
Initial view and Web Part properties.

Initial
Web Part #1

Initial
Web Part #2

PS.  This is not the prettiest tool in the world but was simply a proof of concept I wanted to check out, thought I would share it with everyone.

1 Comments:

Anonymous Anonymous said...

hearwhat.blogspot.com is very informative. The article is very professionally written. I enjoy reading hearwhat.blogspot.com every day.
cash advance loan
loans

November 24, 2009 at 6:13 PM  

Post a Comment

<< Home