SharePoint 2013:How to Show the ID Field in EditForm.aspx and DispForm.aspx
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
- Go to the list.
- Click view item with any existing item or if you do not have any item then in the URL after listname add /DispForm.aspx .
- 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.
- 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>
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.