I am trying to create an ASP workflow task form. It should contain two types of fields:
- fields from related item (on which WF was started);
- 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!
!Page.IsPastback
construction?