Sunday, January 20, 2008

Customizing SharePoint 2007 List Forms (DispForm.aspx, NewForm.aspx, EditForm.aspx)

[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.

  1. Right click on the list (ie. Contacts) then go to New->ASPX.
  2. Rename the form to something that makes sense (ie. NewContact.aspx)
  3. 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.

  4. 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.
  5. 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.
  6. 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).

Ok, that's it for now. Good luck.

-Tyler

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....

Thanks in advance,
Mohana

Tyler Holmes said...

Hey Mohana,

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.

HTH,
Tyler

Anonymous said...

Hello Mr.Tyler Holmes,

Thanks for the reply.

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.

I'm badly struch tyler...

Anonymous said...

Tyler i missed out one thing,

My URL has only [Server_name]/_layouts/AccessDenied.aspx

And it doesn't have any parameter called source

Tyler Holmes said...

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.

Let me know,
Tyler

Anonymous said...

Thanks Pal,
I did not set the ITEM Level Permission for that list properly....
Now everything seems to be fine....

Millions of Thanks ya...

Totoy Bato said...

Hi,

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?

Tyler Holmes said...

@totoy bato

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!

Hope that helps,
Tyler

Anonymous said...

Hi Tyler,
Is there a way to modify (customize) a ListFormWebPart? I would like to remove the UserName link in the "Created by" and "Modified by" lines that are part of an Annoucement. Thanks.

Anonymous said...

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!

Tyler Holmes said...

You're very welcome. Thanks for the feedback!

Joel Daniels said...

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.

Thanks,
Joel Daniels

Tyler Holmes said...

Hey Joel,

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.WebPartPage
2) 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.

HTH,
Tyler

Anonymous said...

If I create a new Newform.aspx on development is there a way to deploy this to a production server without using Sharepoint Designer?

Anonymous said...

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 Holmes said...

Unfortunately I can't think of a way of doing this w/out writing some custom ASP.NET web forms.

Would it be possible for you to provide some tabbed show/hide navigation that only shows half the form inputs at one time?

It might be a fair compromise.

HTH,
Tyler

Anonymous said...

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... :(

Bhakti Chouksey said...

HI System.What

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.

if yes then please describe me ..
I'm waiting for your reply.
thanks
BHAKTI CHOUKSEY

Chetan said...

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.

Tyler Holmes said...

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).

HTH,
Tyler

Justin said...

Hello Tyler,

I have a 3 part question:

I have a primary site where a list resides, with 3 subsites that are viewing that list in various means through data views.

Since there are multiple groups that can see various items on the list I'm doing item level security.

3 questions:
Will editing the display form "close" buttons to "goto source" break attachments?

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.

Any help would be appreciated. Thank you.

Anonymous said...

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

Tri said...

Tyler,

I followed the steps, almost successfully.

My problem lies on step number 5.

I right-clicked on my custom list ... chose Properties ... clicked on Support Files... clicked on Browsed ... and assigned to the new form ... OK ... Apply ... OK

But it still not change the configuration to the new form

I, immediately, go over step 5, and see that it is still pointing to the old form

I am not sure how to trouble shoot this issue

Any helps are greatly appreciated

Anonymous said...

Tyler,

I followed the steps, almost successfully.

My problem lies on step number 5.

I right-clicked on my custom list ... chose Properties ... clicked on Support Files... clicked on Browsed ... and assigned to the new form ... OK ... Apply ... OK

But it still not change the configuration to the new form

I, immediately, go over step 5, and see that it is still pointing to the old form

I am not sure how to trouble shoot this issue

Any helps are greatly appreciated

Bear said...

Hi Tyler,

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?

Randy 'Bear' Schmidt

Tyler Holmes said...

Hey Bear,

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.

Best,
Tyler

Bear said...

Hi Tyler,

First, thanks for responding so quickly. I appreciate it.

I've tried copying the names of my new fields from the EditForm.aspx; ex: @Request_x0020_Status, but no luck.

That's why I was wondering if there was a setting or something I had missed. I can see the data in the fields in the list itself and on the EditForm, but not on DispForm. Makes no sense.

One very unhappy Bear

remandlo said...

Good article however, when I click on View item the custom display form I created and associated with the list does not display. My list is still displaying the default DispForm.aspx

Anyone came across this issues?

Adapt software India said...

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 the
control 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.

Sharepoint developer
Sharepoint Site
Sharepoint Services
Sharepoint Designer
Sharepoint Consulting
Sharepoint Server