I'm working on a migration project from 6.5 to 8.2. I've installed a clean WFFM 8.2 and I'm trying to refactor the existing code.
It adds the WFFM form programatically as follows:
ASCX
<div runat="server" class="grid_13" id="OpeningFormDiv">
</div>
ASCX.CS - original code
FormRender Form = new FormRender
{
FormID = GetParameter("FormID"),
ReadQueryString = GetParameter("ReadQueryString"),
FormTemplate = "/sitecore modules/web/Web Forms for Marketers/Control/SitecoreSimpleFormAscx.ascx"
};
OpeningFormDiv.Controls.Add(Form);
ASCX.CS - "new" code
SitecoreSimpleForm form = new SitecoreSimpleForm(Sitecore.Context.Database.GetItem(GetParameter("FormID")));
var test = new FormRender(form);
OpeningFormDiv.Controls.Add(test);
the new code has the same effect (and basically does the same thing). both throw and exception stating that the innerItem is empty:
Server Error in '/' Application.
Value cannot be null.
Parameter name: innerItem
Description: An unhandled exception occurred during the execution of the current web request.
Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: innerItem
All the code samples I've found online are using this method, so I think I'm on the right track here. Does anyone have an idea what might be wrong? When debugging the FormId and Querystring parameters are retrieved correctly and the SitecoreSimpleForm is created as normal. The error occurs when the form is added to the controls of the div.
Context.Database
is correct and all required items have been published?