I was attempting to re-use a ListFormWebPart in a custom webpart which would be placed on a publishing page, in this case the webpart would display the metadata properties for document library items using custom rendering templates, with the parameters for the List and Item Id’s being supplied by page querystring parameters.
The initial code for creating the ListFormWebPart in CreateChildControls was as below;
_form = new ListFormWebPart { ID = "lfwp_display", ChromeType = PartChromeType.None, ControlMode = SPControlMode.Display, FormType = 4, TemplateName = "CustomRenderingTemplate", ListName = list.ID.ToString("B").ToUpper(), ListItemId = document.ID, Title = "List Form", AllowClose = false, AllowConnect = false, AllowEdit = false, AllowHide = false, AllowMinimize = false, AllowZoneChange = false, ViewFlag = "1048576" };
This all worked well it seemed, until I noticed that the same ListItem was being displayed, as though the query string parameters were being ignored, until I recycled the Application Pool and refreshed the page.
I managed to fix this issue by creating a unique ID value for the webpart each time CreateChildControls was called, incidently using the novel form of ID quirky to the ListFormWebPart, i.e. g_4b507cf2_8d12_4e1a_9799_cab82a8147f0.
Changing the code as follows solved the problem;
var wpid = Guid.NewGuid(); _form = new ListFormWebPart { ID = "g_" + wpid.ToString("D").Replace("-", "_").ToLower(), ChromeType = PartChromeType.None, ControlMode = SPControlMode.Display, FormType = 4, TemplateName = "CustomRenderingTemplate", ListName = list.ID.ToString("B").ToUpper(), ListItemId = document.ID, Title = "List Form", AllowClose = false, AllowConnect = false, AllowEdit = false, AllowHide = false, AllowMinimize = false, AllowZoneChange = false, ViewFlag = "1048576" };
Published by