Custom Web Part Development UI Options

Posted: May 1, 2007 in MOSS 2007

          So I recently got on a project that involved me finally putting some of my theoretical knowledge of custom web part development around MOSS into practice. For those of you who know nothing about these. Basically, in oversimplified terms, a custom web part is a specialized server control. If you have not coded server controls, this is not much more difficult than normal ASP.Net 2.0 coding except take out the nice HTML/Design view UI designed and go back 5 years to classic ASP coding. So if you like doing nitty gritty HTML generation, well you are about to trip into heaven. For the rest of us, well what can I say…this is a serious deficiency on MS’ part.
          Not to worry, if you have a client who is willing to accept it there are options. You could utilize the "Son of Smart Part" which is a web part that serves as a container for standard ascx controls. In SPS03 I had used its predecessor and another called the User Control Container. The issue with some of these is they do not always include the source code so you have to trust the author. It is used quite widely though so I would hope if there is something devious in there, it would be noticed by now, but if you have a client who has strict HIPPA, DOD, or other compliance issues and you cannot afford a 3rd party control from an untrusted source (at least not trusted by your own organization), you could roll your own. Given the time you will save not continuously rewriting your Web part UI’s will be significant, it would be worth your effort to invest some time.
         Another option…amongst the web parts out of the box with MOSS you got you standard page viewer. You could host your "web part" as a standalone ASP.Net 2.0 web site and embed it in a web page viewer part. This is another option I have used, especially when specific requirement of the application  or the underlying technology require it.
         To be sure these are workarounds but they do work and work very well. If you do decide to roll your own web part and are willing to invest in slogging it through generating your own UI, then I have a couple pointers for you. First of all, build some helper classes to generate your HTML. My first swipe through this, I got a table helper, that generates table, tr, td, etc tags for me. It provides a simple way to code the UI and significantly shortens the source code. I also have helpers to generate the ASP.Net controls (since I actually need my web part to say more than "Hello World".) I am in the process of pushing the MS ASP.Net 2.0 AJAX controls out into my web parts, as soon as I complete that I will let Y’all know how it goes but so far I am impressed with those as well.
          Now one other option I wish I could say I came up with, but I didn’t and it was just plain cool. I had done something like it way back when XML first came out in the classic ASP age. You can create web services, or BL classes to generate dynamic sections of your UI data in a standard XML format then transform it with some XSL files. Now the one I saw was so generalized that you could feed just about any data through it you’d like and just plug it into different xsl files through the Web part properties (If you use web services you can also set these in that property pane within MOSS itself).
          Hopefully, this gives you enough information to go forth and be dangerous. I would like to thank Brian Sok for the assistance and brain dump in getting me to the point where I can somewhat intelligently develop these things.
         One other note, to be fair to MS, word is there is some type of update coming for the visual studio 2005 to finally bring these into the IDE and allow a clean and less insane way to generate UI’s. I would have to say I am EAGERLY awaiting anything in that area, and have been so since I coded my first SPS03 web part.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s