Content Types can sometimes get in your way…

…but we have ways of dealing with these critters.

I had a situation with a client whereby I wanted to introduce the use of Content Types for a custom list, but I soon discovered that I needed a slightly different behavior than you would apply CTs to. In this case, I did have a different column set for each type that I wanted to define/use – no problem. I also wanted a different set of required fields for each type, even though there was overlap between the columns used for each CT – also no problem. I also needed a custom NewForm.aspx for each CT – OK, that’s no problem either. The default EditForm.aspx  (or more to the point, the ListFormWebPart control) should have been good for both cases – or so I thought.

Now the tricky part.

As it turned-out, when the defintion of each content type is non-overlapping, something that is usually desirable or at least acceptable, the standard process you would follow to create these custom types leads you smack into a dilema. If you want the EditForm.aspx to behave the same way for each and every Content Type – good luck.

In other words, I needed a different input form for each type, but I also needed a single all-encompassing item editing form for all Content Types. You’ll recall that the standard EditForm.aspx page will present just the columns that correspond to that type. You can select another CT while in the editing form, but that’s clunky.

I solved the problem in a simple way. I based all the new Content Types on Item, but made them identical in terms of their column definitions. This then gives you a different problem, but one that is very easy to fix, because you do end-up with more columns than you want to see in the input forms. No matter though, you just throw a little JavaScript + DOM + CSS in the mix to turn-off the columns you want to hide. Now you have your customized NewForm.aspx form pages, your unique required fields, AND one EditForm.aspx page to use for all CTs and that essentially works as if the CT was Item.

It’s like calling the base class in a derived type – wee!


About generation12

I am a SharePoint/.NET consultant in the twin cities.
This entry was posted in Customization and tagged , . Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your 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 )

Google+ photo

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

Connecting to %s