Archive for November, 2007

Wednesday, November 28th, 2007

ASP.NET Life Cycle

The ASP.NET page life cycle, control or web part life cycle for that matter, is an important concept to know and to understand in ASP.NET web development. ASP.NET, the successor of ASP, introduced the concept of object oriented development. The complete page and its controls are now objects which behave in a child-parent relationship and go through a complete life cycle of their state. It’s pretty crucial to know what stages they go through and which events are called as the web is a stateless medium and we are trying to make a statefull environment out of it.

The key concept is the view state. This is an object, stored within the page, which enholds the states of all current objects. It is loaded, processed and saved during the life cycle. More specifically, it will load all data into the controls right before entering the load event. From this event on, you’ll have controls which are loaded with all previous data. You can manipulate those just until the PreRenderComplete event. Once this event has passed, the viewstate will once again be saved into a hidden control on the page. So things you change during the render event will not be taken into account.

Here is a graphical overview:

ASP.NET Page Life Cycle Overview

Couple of remarks with this diagram:

  • The dark gray events are only available for the page object.
  • The green area indicates events where the viewstate is loaded and avilable in the controls. Once changed the controls will be saved back to the viewstate.

As I said, the viewstate is a pretty important concept to grasp. So, please take time to fully understand it. It’s crucial to know when and where you can interact with it or you’ll be in a whole world of pain when creating interactive web parts or pages. Untill next time, take care!

Sunday, November 18th, 2007

SharePoint SDK’s

Today I’ll be reviewing the SharePoint SDK’s. I’m not saying they are bad, but I’ve never found any good overview about ‘em. And I guess such an overview can be usefull, especially for people starting with SharePoint.

Before we begin, let me explain what a SDK is. A SDK is a Software Development Kit. It’s a set of resources designed to help understanding a specific technology. Sometimes a SDK is necessary to allow development with such a technology. (I’m thinking about the Java SDK) So, what are those resources? Well, it depends. They can include a lot of things. But most of the time, you’ll find documentation (CHM’s and the likes), samples, tools, templates, … you name it. Really usefull stuff.

SharePoint SDK’s come in different flavours. There is the online MSDN section with all the documentation, together with links to seperate downloadable resources. Or you can directly download the SDK. This download will include the documentation, samples, etc, but is suited for offline use, as an internet connection is not required once installed.

So what are the SharePoint SDK’s? First off, there is the Windows SharePoint Services 3.0 SDK. This SDK will only cover WSS related topics. And although it’s quite usefull, the offline installer includes only a couple of files, more specifically: the actual WSS 3.0 reference and a compilation of technical articles. Both can also be found on the online version.
The Microsoft Office SharePoint Server 2007 SDK is much more interesting. It includes both WSS files, and adds much more reference on the MOSS-only technologies. Also, it features some nice samples with source code. This gives us the opportunity to catch a glimpse at how the guys at Microsoft are using SharePoint, which is quite nice if you’re starting off with SharePoint and have no idea how to begin development. The MOSS 2007 SDK also includes the Enterprise Content Management Start Kit (ECM Starter Kit). This starter kit gives some in-depth information on the new ECM features and platform in Office SharePoint Server 2007. Moreover the starter kit is the collection of some white papers and code samples.

Next is a handy overview for the SDK’s:

Windows SharePoint Services 3.0
WSS 3.0
Microsoft Office SharePoint Server 2007
MOSS 2007
Online SDK
 - location link link
 - latest revision April 2007 July 2007
Downloadable SDK
 - location download download
 - latest revision 1.2 (August 2007) 1.2 (August 2007)
 - size 36.2 MB 175.8 MB
 - ECM Starter Kit not included included
 - contents Documentation
- WSS3SDK.chm
- WSSSDK_TechArticles.chm
Documentation
- WSS3SDK.chm
- MOSSSDK_TechArticles.chm
(includes WSSSDK_TechArticles.chm)
- OSSSDK2007.chm
- OFS12sdk.chm
- ECM WhitePapers (8)
Samples
- Records Management (1)*
Samples
- Business Data Catalog (5)
- Content Processing (2)
- Records Management (6)*
- Search (2)
- Web Parts (1)
- Workflow (13)
* The common sample is the IRM Document Protector
Tools
none
Tools
- BDC Definition Editor

In short, the MOSS SDK completely covers the WSS SDK. And even if you don’t have MOSS, the MOSS SDK is still very interesting and worth the download, as the samples give a great in-depth look at coding for SharePoint. ’till next time!

Friday, November 9th, 2007

SharePoint Branding Issues: Web Parts

This final blog post (for now) in the SharePoint Branding Issues series is one regarding web parts and their branding issues. I’m assuming most of you know what web parts are. They are like mini applications within a web page. As they are so small, you’ll often add several of them together on the same web page. In other technologies, such applications are called widgets or gadgets or whatever. But basicly, their ideology is the same. A nice example is featured on live.com.

To get back to .NET, web parts are a new technology within ASP.NET (and unified in version 2). In previous versions of SharePoint, they used some custom made framework. And now in WSS 3.0, they are slowly migrating to the new ASP.NET 2 standard, which allows far more easy web part development. Finally to be complete, a few more statements regarding web parts. Web parts are placed within horizontal or vertical web parts zones. These zones can define the chrome style used for the web parts within. The web part chrome, for those who do not know, is a fancy word for its border decoration. Furthermore, the web parts need one single web part manager, per page, for.. well.. managing purposes. Finally, all of these concepts have a corresponding class within the System.Web.UI.WebControls.WebParts namespace. And basicly this is, in a nutshell, what web part infrastructure is all about.

Now, the thing with SharePoint. They decided to overwrite all of these classes (just as we would for a custom branding job in ASP.NET). But somewhy they made the decision to make the new classes all sealed. So basicly you can not change anything, except, of course, if you rewrite every single class… :-) I know… And as one of my hungarian colleagues would say in such a situation: nice! ;-)

The chrome in SharePoint consists of 5 fixed chrome types (Default, None, Title and Border, Title Only and Border Only). These are implemented in an internal SPChromeHelper. What this class does, is adding the following structure as chrome:

<table>
    <tr>
        <td>
            <table>
        </td>
    </tr>
    <tr>
        <td>
            <div>
        </td>
    </tr>
</table>

Depending of the style the first row, which is the header, will be generated or not. Accordingly CSS classes are attached to the rows, the inner div and the inner table. As you can imagine, this kind of structure can be really restrictive. It is very difficult to add gimmicks, like rounded corners, to such a composition.

What can we do then? Well, basicly, applying tricks and hacking our way in. To achieve this, once again, our friend is CSS. By adding some classes to the right place and by using some specific CSS selectors, one can manage to achieve some degree of customization. A possible solution could be to add a specific CSS tag name to the declaration of the zone tag in your page. This way you can reach its inner web parts through the use of CSS selectors. In most cases you can define your own zones, so this can potentially be a solution for the problem. Another, more obvious solution, consists of simply overwriting the fixed chrome type’s CSS styles. The issue here is that every web part has to be set with the correct fixed chrome type to display your customizations. Of course, you still have the same limitations as the previous solution, as the structure of the chrome is still the same. More over, you usually cannot reach all generated HTML tags using only the fixed CSS class names.

While writing this article, I found this post written by Daniel Terborn. Daniel tackled the same problem and supplied another possible solution. He decided to create a base web part which implements all of the layout. Finally, with some CSS hooks, he manages to get really nice web parts. The problem with this solution is that it only applies to custom written web parts. In some situations this can be acceptable (by only using custom web parts), but most of the time you’ll want to use the out-of-the-box web parts too, for obvious reasons.

Conclusion? There is no clean and neat solution for web part branding within the current iteration of SharePoint products. We can only hope the sealed classes will be opened up in future versions. Until then, happy SharePointing.