I am working on a project that requires code behind in the dispform.aspx as well as the edit and new form. The reson being, I am synching to a web service, on view of an item, I want to make a sall to the web service to get updated data on the record in SharePoint.

I've looked a list definitions, using delegate controls (I was able to link delegate control but unable to find controls in the display form, seems they are in a table without ids etc)

I have created an application page in an empty SharePoint project in Visual Studio 2010, added a listviewwebpart (rather use instead of dataview because the lookup values are displayed as hyperlinks). This page resides in the _Layouts folder.

The question is, how do I add code behind to the OOB dispform.aspx page without having to use list definitions, etc. If I can use the form I created in the layouts folder, can I use this for my list display? (SharePoint 2010).

2 Answers 2


As you already discovered, one way is to use the DelegateControl approach (with PlaceholderAdditionalPagehead) and that's in fact what I've been using for a couple of years now.

The key is how to access the built-in editform.aspx/dispform.aspx pages with the embedded WebPart showing the SPListItem. That's done by hooking your WebControl into OnPreRender/OnLoad to check SPContext.Current.FormContext.FormMode if you are on a SharePoint form page.

Then you need to find the ListFormWebPart and get your hands on the fields you are looking for.

Basically something like the pseudo-code below (though it is much simplified for brevity):

First, get the ASP.NET controls of the current page:


Then find the ListFormWebPart (either loop recursively or use another smart way to find it deep down the controls collection):

if (typeof(ListFormWebPart) == childControl.GetType())
ListFormWebPart listFormWebPart = (ListFormWebPart)childControl;

Finally, dive into the controls collection of the ListFormWebPart to find the ListFieldIterator control (again, either loop recursively or use another smart way to find it deep down the controls collection) which itself contains a collection of the actual fields of the SPListItem. E.g. for a text field:

if (typeof(TextField) == formFieldChild.GetType())
  TextField textField = (TextField)formFieldChild;
  if (textField.FieldName == "YourFieldNameGoesHere")
    // Get the field value and do with it whatever you want
    string myFieldValue = textField.Text;

Another way would be to use client-side JavaScript and the CSOM to pull data from the selected item (e.g. by getting the SPListItem ID from the Url of Dispform.aspx and query the SharePoint Webservice via REST/SOAP) and push it via XmlHttpRequest to your custom WebService.

Finally, the last thing that comes into my mind is to develop a custom ControlAdapter to hook into the ListFormWebPart and read its fields etc., though I haven't tried this myself because I'm quite happy with the DelegateControl approach mentioned above.

Hope that helps.

EDIT: Added a few lines to clarify things a little bit more.

  • 1
    thanks, wonderful treasure hunt down in the template containers, but was able to find it, make the seb service call and update the listitem. DelegateControl is a great means to do this, I just needed to recursively go through the controls. Thanks!
    – Gary Mc
    Mar 11, 2013 at 18:30

Here are two possibilities for getting custom code on a list page:


You could also use InfoPath. In SharePoint 2010 you can customize the list form to use InfoPath for new/edit/display forms. And in the InfoPath form, you can use code behind or the built-in functionality of InfoPath to call your web services.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.