I am trying to create an ASP workflow task form. It should contain two types of fields:

  1. fields from related item (on which WF was started);
  2. fields from task (such as Due Date).

For that I try to use SharePoint:FormField control. As it should show information from different lists, I change context for related item controls in the code-behind as follow:

        foreach (var control in relatedItemControls)
            control.ListId = listId;
            SPContext context = SPContext.GetContext(HttpContext.Current, itemId, listId, web);
            control.RenderContext = context;
            control.ItemContext = context;
            control.EnableViewState = true;

This approach works well and I could see actual information from both task and related item.

However, after a postback I can't change context of the relatedItems controls. Or more exactly, I try to do it in several places (in Page_Load, CreateChildControls, EnsureChildControls, button click handler), but anyway after postback I could not see information from the related item list.

Instead of it I could see data from the task for FieldName="Title" (both lists have the Title field) and something like "["Project" column value]" on other controls.

So it seems, like context was not changed.

I ran out of ideas what I could try to fix or troubleshoot the issue.

Possibly, I should do something additional to bind items after changing control context or should change context in another step of ASP lifecycle or even this approach (to have two different contexts on the same page) should not be used at all.

Could you help me, please. Every suggestions are very appreciated.

PS: I would be grateful if anybody could suggest me some good books or articles, where I could read about best practices of ASP workflow task forms creation and ASP page lifecycle.

Update1: I tried to change context in Page_Load, in CreateChildControls (in this case I can't see data from relatedItem even on the first load). I tried wrap it in !Page.IsPostback, but all to no avail.

Update2: In the aspx file I define controls as follows:

<SharePoint:FormField ID="RI_ServerName" runat="server" FieldName="Title" ControlMode="Display" />

Additional solution. Also I found that when I do this changes in LoadViewState event of the page it works!

  • are you sure that you code is not invoked in !Page.IsPastback construction?
    – Alexander
    Jan 22, 2013 at 11:30
  • Thank you for the comment. Yes, I tried both cases (to place and not to place it inside !Page.IsPostback), both don't work. Any other ideas?
    – MikhailSP
    Jan 22, 2013 at 11:35

1 Answer 1


where are you putting the code? i presume the createchildcontrols? also the values before postback need to be stored into session state and the values to put back into session state after postback is onPreRender:

more info can be found here:

How to save variables per user session per page

have you tried encapsulating the code with:

if (!Page.IsPostBack) { your code here } 

for sharepoint lifecycle:



Ok, i think i understand what your trying to do. Try the following:

<SharePoint:FieldValue ID="RI_ServerName" runat="server" FieldName="Title" ControlMode="Display"/>


<SharePoint:FormField ID="RI_ServerName" runat="server" FieldName="Title" ControlMode="Display"  ListId="{title list guid}"/>


hope it helps :)

  • Thank you very much for the reply. I have added update to the post. As far as I understand, I don't need to save state of contols in my case (I use SharePoint:FormField controls).
    – MikhailSP
    Jan 22, 2013 at 11:52
  • just ammended my answer ;)
    – Ali Jafer
    Jan 22, 2013 at 12:03
  • It seems like adding ListId="{title list guid}" and ItemId for FormField control as you proposed works well. But for my case it is not so convenient (as I related item list Id could be different in different cases), but it could help somebody. Also changing control to FieldValue works with my code-behind.
    – MikhailSP
    Jan 22, 2013 at 12:32
  • 1
    Thank you very much! Small addition, it seems that FormField control works not as expected only when its ControlMode="Display". When it is "Edit" it works well.
    – MikhailSP
    Jan 22, 2013 at 12:42
  • +1 for the find :)
    – Ali Jafer
    Jan 22, 2013 at 12:58

Your Answer

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

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