Monday, February 25, 2008
Web Parts generator tool
From the moment I started working with Web Parts and portal framework the thing that I missed the most was a designer that I could use to create and separate Web Part's design/layout from the "code behind". The way Web Parts are supposed to work is similar to Web Server Controls meaning that you have to add all the controls manually to Controls collection and you have to render them from your code "manually".
Some time ago I read a great article made by Michiel Van Otegem about skinned controls. Based on his idea and based on functionality of his SkinnedPart class I made BaseSkinnedWebPart which is a slightly improved Michiel's control. BaseSkinnedWebPart allows us to create Web Part's design/layout in an ASCX control and use it as separate file (skin) that defines the layout of Web Part and specifies all the controls of the Web Part.
Time saving solution
The thing that still bothered me a lot is that I had to write a lot of code just to assign all server controls from ASCX to member variables in Web Part, to validate if required controls are present in ASCX or not and similar common things. In a project I was involved in recently we had a Web Part with near 350 server controls so just to create initial Web Part class with all server controls from ASCX (skin) I had to type more than 1000 lines of code risking that I'll make a mistake and spending a valuable time.
In order to overcome that I got to idea of writing a generator tool that will generate the initial Web Part class with all the assignments, validations etc based on previously made ASCX control (skin for Web Part).
After some time I made the first version of the generator tool (called it swpgen.exe) and published it on codeplex. You can check the project’s home page here or first release’s page here
I also published an article on codeproject describing the details on how to use swpgen.exe generator tool. You can read it here
Labels: ASCX, MOSS, Portal Framework, Web Part
posted by Popovic Sasa
Links to this post:
+ Blog Home