How to Show the ID Field in EditForm.aspx and DispForm.aspx in SharePoint

How to Show the ID Field in EditForm.aspx and DispForm.aspx in SharePoint

We do not get ID field in DispForm.aspx and EditForm.aspx pages out of the box. However many times business needs this field to show up in this form because of their uniqueness. To accomplish it a javascript is most easy option and it can be applied via content editor webpart. To do this follow these steps

1. Go to the list.
2. Click view item with any existing item or if you do not have any item then in the URL after listname add /DispForm.aspx .
3. In the next page add ?ToolPaneView=2 . This will open the page in editable form and the add a content editor webpart. Edit it to add the HTML content.
4. Paste the below script:

<script language="javascript" type="text/javascript">
 
_spBodyOnLoadFunctionNames.push("showID");
 
function showID()
{
 
var querystring = location.search.substring(1, location.search.length);
var ids = querystring.split("&")[0];
var id = ids.split("=")[1];
var Td1 = document.createElement("td");
Td1.className = "ms-formlabel";
Td1.innerHTML ="<h3 class ='ms-standardheader'>ID</h3>";
var Td2 = document.createElement("td");
Td2.className =  "ms-formbody";
Td2.innerHTML = id;
var Tr1 = document.createElement("tr");
Tr1.appendChild(Td1);
Tr1.appendChild(Td2);
var Location = GetSelectedElement(document.getElementById("idAttachmentsRow"),"TABLE").getElementsByTagName("TBODY")[0];
Location.insertBefore(Tr1,Location.firstChild);
}
 
</script>

5. save it and exit.

The same process you need to follow in case of EditForm.aspx as well. The ID field will be shown in read only mode in both the forms.

For Sharepoint 2010 content editor webparts can be edited in the following way  http://social.technet.microsoft.com/wiki/contents/articles/how-to-add-html-content-into-content-editor-webpart-in-sharepoint-2010.aspx . You can use same script here as well but in sharepoint 2010 these forms open in form of modal windows so if you want to edit them you need to use direct URL.

I hope this will help you out.

Thanks,
Rahul Rashu
Leave a Comment
  • Please add 4 and 7 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Richard Mueller edited Revision 6. Comment: Changed tag "SPS 2010" to "SharePoint 2010"

  • Richard Mueller edited Revision 4. Comment: Replace RGB values with color names in HTML to restore colors

  • Richard Mueller edited Revision 3. Comment: Removed (en-US) from title, added en-US tag

  • Craig Lussier edited Revision 2. Comment: added en-US to tags and title

  • Ed Price - MSFT edited Revision 1. Comment: Updated title casing and "SharePoint" casing/spelling. Great article!

Page 1 of 1 (5 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • Ed Price - MSFT edited Revision 1. Comment: Updated title casing and "SharePoint" casing/spelling. Great article!

  • Craig Lussier edited Revision 2. Comment: added en-US to tags and title

  • Richard Mueller edited Revision 3. Comment: Removed (en-US) from title, added en-US tag

  • Richard Mueller edited Revision 4. Comment: Replace RGB values with color names in HTML to restore colors

  • It works like a charm with SP 2010 and 2013, thanks!!!

  • Richard Mueller edited Revision 6. Comment: Changed tag "SPS 2010" to "SharePoint 2010"

Page 1 of 1 (6 items)