Deploy Custom List Forms in Sharepoint - Part II

I'm back... So let's get started with the next part of explaining what I did to get custom forms deployable.
 
As written in the first part, I'm using code behind in the custom page. The code is pretty easy as it just will look for a ListFormWebPart object on the SP page and hides it.
The next question that comes up is, when can I check for the ListFormWebPart. It turned out that SP itself is checking every time the page is displayed if the WebPart exists on the page and if not adds it. The first chance in the ASP.NET event cycle after SP adds it is OnInitComplete. So I added the following code there:
 

foreach (WebPart webPart in Main.WebParts)

{

    if (webPart is ListFormWebPart)

    {

        webPart.Hidden = true;

        ((ListFormWebPart)webPart).ControlMode = SPControlMode.Display;

    }

}

 
Let me point out some things here - first, the variable Main. It is defined as a field in my class.
 

protected WebPartZone Main;

 
Main is actually the default name for the WebPartZone in a standard SP form page. Using the ASP.NET control binding, I get access to the web parts there. Btw this zone has to exists otherwise SP will add it automatically to add the ListFormWebPart. So we can be somehow sure, that it will not fail if we access it.
Next, the loop. We simple loop thru all available WebParts until we find the desired one. Once found we cannot delete the WebPart, but hide it.
You might wonder what ControlMode is good for. It actually defines how the ListFormWebPart will display the data fields from the current entry - possible values are New, Edit, Display and Invalid. As we don't want to deal with the WebPart, we set it to display, also to avoid double entries when editing the data.
 
That's the magic trick - nothing more.
 
To wrap it up, in my SP project I created a very simple class that derives from Microsoft.SharePoint.WebPartPages.WebPartPage and acts as a base class for my custom pages. Here the complete code of it:
 

namespace FC.SP.MyApp

{

    public class PageTemplate : WebPartPage

    {

        protected WebPartZone Main;

 

        protected override void OnInitComplete(EventArgs e)

        {

            base.OnInitComplete(e);

            foreach (WebPart webPart in Main.WebParts)

            {

                if (webPart is ListFormWebPart)

                {

                    webPart.Hidden = true;

                    ((ListFormWebPart)webPart).ControlMode = SPControlMode.Display;

                }

            }

        }

    }

}

 
Next post I will talk about the usage of this class in my pages.
 
Links:

Published: Feb-03-09 | 0 Comments | 0 Links to this post

Deploy Custom List Forms in Sharepoint - Part I

I did several SharePoint customizations with the focus on making them deployable. Although SharePoint 2007 is way better than previous versions, this can still be a big challenge, as there are a lot of hard-wired behaviors you have to work around.

 

This also applies to List forms. When using SharePoint Designer, customizing these forms is no problem. But when deploying them together with a custom list, the fun starts.

 

The problem is that SharePoint always needs a List Web Part in the page. If this Web Part is not included SharePoint will add it automatically. In my pages I also needed to use other means to display data from the list, so I had to replace the standard forms with custom forms.

 

When using SharePoint Designer you are able to manually remove this standard Web Part and all is fine from there on.

 

The only way around this problem is to remove the List Web Part when the custom form is displayed – this is done via some code behind. In short, I created a class that will act as my page template and all my custom pages will derive from it.

 

In the next part I will show in detail how this is done. In the end we will have a deployable solution that contains a custom list using custom forms.

 

Here some interesting links for forms customization:

Creating Custom List Forms for Creating, Editing, or Displaying a List Item

Customize the "NewForm.aspx" page for a SharePoint List

 

Deploy Custom List Forms in Sharepoint - Part II


Published: Nov-29-08 | 1 Comment | 0 Links to this post

The FC founders go all the way!

A year ago I would have called anyone crazy who would have told me that I would run a marathon in 2008.
Marathon Man
 
I had started to jog to get back in shape when my co-founder Jennifer signed us up for the Berlin marathon. Of course she knew that I am not the kind of guy to chicken out, so I had to step up my training and find the time in between running a start-up company and being a father and husband to go for long distance runs multiple times a week over the coming 7 months.
 
At the end of September we just finally did it. It was awesome. I was amazed that it wasn't the pain everyone had predicted it would be. Even "the wall" I was supposed to hit at the 30km mark didn't happen. It was just a great sunny day out that I enjoyed, thanks to all the proper preparation.
 
I just recognized how much that marathon has in common with my work: Building solutions for customers can sometimes be quite lengthy too. And being prepared is as important as is the capability to endure "the extra mile" when a project doesn't lift off right away. It is all about being able to follow through, especially when there is no shortcuts. And the bonus is the same too: there is no better feeling than when you go all the way, even when it's 42.195km.

Published: Nov-13-08 | 0 Comments | 0 Links to this post