AI OnAI Off
public class XFormControl2 : EPiServer.XForms.WebControls.XFormControl, INamingContainer
{
public object WizardContext = null;
public delegate bool IsMePostingDelegate( object wizardContext );
public IsMePostingDelegate IsMePosting = null;
protected override void OnInit( EventArgs e )
{
base.OnInit( e );
this.Load += new EventHandler(Control_Load);
}
protected override void LoadViewState( object savedState )
{
// load Data from viewstate
Data = (XFormData)savedState;
EnsureChildControls();
}
protected override object SaveViewState()
{
// persist Data to viewstate
return Data;
}
protected void Control_Load( object sender, EventArgs e )
{
// only read values if it was "our" form that was posted
// otherwise we will read empty values "over" any previously read
// this is crucial when placing xformcontrol on wizardsteps
if( null==IsMePosting || IsMePosting( WizardContext ))
ReadPostedValues( Data );
}
}
2)
I added a "IsMePosting"-delegate so that the containing wizard may specify a
function to be executed to determine if it's _this_ wizardstep's thats being
postbacked, in which case the Data will be read from posted values through
the call to ReadPostedValues()
This also requires you to "remember" the previous wizardstep, and in the
delegated IsMePosting check if its the same as the idnex stored in the
xformcontrol's WizardContext
The wizardSteps are created dynamically during page OnInit() in code similar
to this:
//loop through all child xformpages of this page
int stepindex = 0;
foreach(PageData child in GetChildren( CurrentPage.PageLink ))
{
WizardStep wizardStep = new WizardStep();
wizardStep.Title = child.PageName;
XFormControl2 xformControl = new XFormControl2();
xformControl.ID = "XFormControl";
wizardStep.Controls.Add( xformControl );
xformControl.FormDefinition = ( (PropertyXForm)child.Property["MainXForm"] ).Form;
xformControl.WizardContext = stepindex;
xformControl.IsMePosting = new SalesForceX.Gui.WebControls.XFormControl.IsMePostingDelegate( delegate( object Context ) { return PreviousStepIndex == (int)Context; } );
WizardSteps.Add( wizardStep );
}
Then, to "collect" all values when clicking the Finish-button, you'd have to iterate
over all WizarSteps and get all contained XFormControls and from them iterate over all
XFormControlBase input controls to retrieve their instance values.
You cannot use the normal XForms submitting to store these values as they're "coming from"
different XForms forms.
Regards,
Johan Olofsson
EPiServer AB
xformControl.IsMePosting = new XFormControl2.IsMePostingDelegate(delegate(object Context) { return PreviousStepIndex == (int)Context; });
The delegate always seem to return false, hence no previuos data is ever loaded. I think I'm missing somthing with the Context
or PreviousStepIndex
. My implementation of PreviousStepIndex is below.
public int PreviousStepIndex
{
get
{
if (ViewState["PreviousStepIndex"] == null)
return 0;
return (int)ViewState["PreviousStepIndex"];
}
set { ViewState["PreviousStepIndex"] = value; }
}
Mvh
Pontus
Page.LoadComplete += new EventHandler( delegate( object sender, EventArgs ea ) { PreviousStepIndex = ActiveStepIndex; } );
Regards,
Johan Olofsson
EPiServer AB
Dictionary fieldValues = new Dictionary();
foreach(WizardStep step in WizardSteps)
{
XFormControl2 xformControl = step.Controls[0] as XFormControl2;
if(null == xformControl)
continue;
foreach(EPiServer.XForms.WebControls.XFormControlBase input in xformControl.ExtractXFormControls())
{
fieldValues.Add( input.Reference, input.GetInstanceValue() );
}
}
I think the trick might be to call "GetInstanceValue()" rather than "Value" for
the XFormControlBase input controls.
Regards,
Johan