Sunday, January 20, 2008

[Updated Feb 27, 2008] It's important to note that customizing forms breaks attachment support! If you're going to be attaching documents to these list items you will either need to write code to upload the attachments yourself or NOT customize the form. This is still not fixed with SP1.When you create a new list in SharePoint, a default form for viewing, editing and adding are provisioned for you by SharePoint. This is also true for any views that you define on the list. SharePoint creates an .aspx page at http://siteroot/Lists/ListName/DispForm.aspx. You can see all these pages using the SharePoint Designer.

Be default they are basically a WebPartZone with a ListFormWebPart inside.

The real story though is that you can customize these lists. Not only can you very easily create your own, but you can tell the list to always use your form. You can even tell the list to use your form for certain Content Types (if the list has multiples) and use the default Form for other Content Types.

Creating a Custom List

In the following example we're going to create a new Form for adding contacts, then we'll have SharePoint Designer change it so that it can use the current master page and participate in any branding effort you may be doing.

Right click on the list (ie. Contacts) then go to New->ASPX.

Rename the form to something that makes sense (ie. NewContact.aspx)

Now we need to turn this blank form into a page that can view content from the list. Double click on the form. Once it's in focus in SharePoint Designer on the toolbar click Insert->SharePoint Controls->Custom List Form (see below). In the popup choose your list (ie. Contacts) and the type of form you want to customize (ie. NewForm). Notice that you can also choose a Content Type to customize the forms for. You can literally have a separate customized 'NewForm' for each Content Type that the list stores. Click Ok and watch as your form gets automagically tee'd up with all the controls it needs allow users to add Contacts to the list.

Now that we have a form that can add new Contacts, lets make sure it enforces our brand by attaching a Master Page. Click Format->Master Page->Attach Master Page. Choose the 'Default Master Page' and watch SharePoint Designer neatly place all the markup that matters inside of a ContentPlaceHolder and attach the current runtime master page.

Ok our last step, we need to tell our list to use our new customized form. Right click on the list in question. Click 'Properties'. Click on the 'Supporting Files' tab and then change the 'New item form' to the .aspx you just made. It's of note that the .aspx needs to be housed inside the list, you can't just house it anywhere.

You're done, head back to your contacts list (in SharePoint and add a new item, you'll see the form that we just made). You can of course do the same for DispForm.aspx and EditForm.aspx.

Here's a screen shot of some text that we changed on the form. Future posts will get into actually working with SharePoint controls and putting a code behind on the form, so you can write some C# to alter the behavior of this form (in addition to changing the declarative markup in this .aspx).

29 comments:

Anonymous
said...

Hello Mr.Tyler Holmes, I'm facing some permission problem with custom list. can you just see whether you can help me out.... I have a user with "Contribute" permission and when the user attempts to click on "OK" in the EditForm.aspx after the modification, WSS throws an error stating that "Access is Denied". Pls help me out....

I'd probably end up troubleshooting this the old fashion way, by trying to gather as much info as I could.

For instance:-Can the user add to the list?-What effective permissions does the user have on the list? Just because they're in the Contribute group) doesn't necessarily mean they can add to the list, someone could have customized security at the list level.-Can you reproduce this with another account (maybe adding a local or a domain account and slowly adding more and more permissions)?-What does the URL look like with the access denied, is it something that this post could help you with?http://blog.tylerholmes.com/2008/02/troubleshooting-access-denied-errors-in.html

I'm sorry I can't outright tell you what's wrong. Worst case scenario, if it's a production machine, back it up and restore it to some sandbox where you can play around and troubleshoot it.

Actually i have a subsite and a few Custom list in the subsite. I have given permission to the subsite and the custom lists inherit from the Parent.The user is able to edit the items in the other list.

Even in the list in which i am facing a problem the user is able to add a new item but not able to edit the existing item.

And for other users, the issue is not getting reproduced. Only for this user. And even i have tried creating the user account again but still the problem remains same.

If i give the user "Full Control" privilege everything seems to be fine.But that should not be done.

Wow that is a little odd. I'd have two other items that you may want to look in to.

1) Look at the item itself that the user is trying to edit. It may have it's own permissions (not inherited), you can do this by finding the item in the list, and then clicking into the Manage Permissions option in the list items context menu. Check the users rights here, ideally they've been inherited down all the way from the site. Either way you'll be able to see what the users effective rights are for this list item (and change them for an individual item too).

2) In the List Settings for the list that is behaving oddly, under Advanced Settings look in the Item-level Permissions and ensure that users can edit 'All items' radio button.

Is there a way to deploy the new form on list using definitions? I've created a couple of custom display forms from dispform.aspx, added it to the list using designer. I would like to create my custom list together with my custom dispforms using feature/ definition.. any ideas?

While I'm not sure what the best practice is I can think of at least one way to get it done.

The first would be to dig through the solution manifest and feature schemas and see if there isn't any type of declarative XML markup that might do this for you. The WSS extensions might help.http://blog.tylerholmes.com/2008/03/walkthrough-creating-sharepoint-feature.html

Failing that you may also consider customizing the form, adding it as a module (see the above link for instructions) and then write some code in a feature receiver (against the SharePoint object model) to assign your form as the custom Disp/Add/Edit form.

All that said I don't have a specific example of either and it would take a couple of hours for me to come up with a demo!

Tyler, your comment above("2) In the List Settings for the list that is behaving oddly, under Advanced Settings look in the Item-level Permissions and ensure that users can edit 'All items' radio button.") just solved something I've been trying to solve for two days. Thanks!

Did you ever post any follow up articles that discuss adding code behind? I've been searching for information on customizing item forms, and I haven't found much beyond doing the basics in SharePoint Designer.

I don't have a specific post on adding a code behind to a list item display form. In terms of the steps I can give you the following.

1) Create a class that extends Microsoft.Sharepoint.Webpartpages.WebPartPage2) Add custom codes that modify controls at various points in the page life cycle.3) Deploy the code (dll) to either the application bin folder or the GAC.4) Change the list form to extend the new code behind.

Hello there this is great, but this is what I need help on. I have a list with alot of columns. On the edit form it contains alot of fields to edit, I was wondering is it possible to seperate this fields on another page or having different edit pages for different fields? My questions is how can I do this? Can I link to the same list and have custom edit forms to edit columns?

Example:

Editform 1:

name:address:phone

Editform 2:requirements:map code:services:payment:

all this columns are all in 1 list I just want to seperate them on different edit forms of course with its unique ID of each column.please help!

Tyler thank you for your respond, How would you go about creating an edit form for a list in share point desginer 2007? I know that normally if this was a sql database I can connect to it and have different pages with a source code and a dataform to edit fields. But with a sharepoint list I have not figure this out. I tried creating another list and I created customr forms for the edit, display and create item and I deleted the fields I wanted on this edit form. The problem with this is that when I click on properties on the list and assign the custom forms to the options it does not work :(. it does not keep the edit form I created it goes back to the edit form used on the other list... :(

I have some problem...1) I'm creating custom list employee form but i also want to provide tab for one more form that is costsheet.so is it possible for me.2) After submitting form in allform.aspx , i want when i will click on particular empno(link) so i want to open a new site form , i dont want to open dispose.aspx who give the details of that particular record.and also want pass parameter of that empno , so on the next page i can do some calculation for display data.Is it possible for me.

I have a visitors group which has "read" permissions on a feedback list. Now I create a custom form say NewForm2.aspx and check it in. Users with "Read" access cannot send in a new feedback, which is correct! What would be a way to allow visitors to create a new feedback thru NewForm2.aspx, other than to give them "contribute" rights? Appreciate you input. Thanks.

That's an interesting question. I'm kind of wondering what exactly you'd like visitors to be able to do on this list (maybe add but not edit/delete)?

You could either:1) Create a permission level that speaks the rights you'd like your users to have (since Contribute isn't doing the trick). You can manage permission levels through Site Settings->Advanced Permissions->[Click on Settings in the Tool Bar]->Permission Levels.

From here you can construct a permission level that you feel is appropriate for the rights users can have on your feedback list. Once that's done, assign the permission level to the visitors group and remove the Contribute permission level.

2) You can also check out the Advanced Settings for your feedback list (List Settings->Advanced Settings). Here you can choose whether contributors can edit only their own items or others (this affects delete as well). And if users can read list items that belong to others (or only their own).

If I'm doing item level security, I can have the correct list items be viewable on the sub sites, but the users do not have access to dispform.aspx. Is there somewhere else I need to specify permissions?

If the list items contain "people" fields, where would I enable view permissions for the userdisp.aspx?

Everything works perfect if I give full read rights to the primary site, but once I shut down the primary site the list items are viewable, but both display forms are not.

Seems like if you choose a differrent display item form under Supporting Files, and you move an item from list a to list b, the item in list b refers to list a.

But designing a form in SPDesigner is easy with this, too bad it doesn't work 100% . The other thing which causes problems is to add a attachment, ms has a kb about this http://support.microsoft.com/kb/953271

I've customized the All Service Request list in the HelpDesk template by adding 6 new columns; 2 dropdowns and 4 basic text. I've used SP Designer to add these to my EditForm.aspx without issue. However, I cannot get these columns to display on my new DispForm.aspx.

When I go to the code for the DispForm.aspx and start typing in:

xsl:value-of select="

The intellisense that appears does not include my new fields. Is there a setting i've missed or something?

I wouldn't use the availability of intellisense in SharePoint Designer as a determinant of whether or not your XSL is correct.

Intellisense consistently comes and goes for me on almost every OS I've used SPD on. I'd use your EditForm.aspx as an example, odds are you're perfectly fine and it's just SPD that's stopped working correctly.

SharePoint Online delivers the powerful features of SharePoint without the associated overhead of managing he infrastructure on your own. Flexible management options ensure that you still retain thecontrol you need to meet the compliance requirements of your organization. You can purchase SharePoint in the cloud as a standalone offering or as part of an Office 365 suite where you could also get access to Exchange, Lync, the Office clients and web apps.

About Me

Tyler Holmes is a Solutions Architect working in Portland, Oregon. He lives mostly in the MS tech stack and is currently treading the waters of Communication/Collaboration and Business Intelligence with off the shelf/open source technologies.