Showing posts with label NewForm.aspx. Show all posts
Showing posts with label NewForm.aspx. Show all posts

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

1 nhận xét

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

(Source:blog.tylerholmes.com)