XForms fails to complete a postback

Vote:
 

We've had XForms running on our site, but several months ago we made a series of changes to our website project and one of them seems to have broken these forms.  In our implementation, we have a dedicated page template and page type for our XForms pages.  In the global.asax, we have the following code in the OnApplicationStart method:

            var xformEvents = new XFormEvents();
            XFormControl.ControlSetup += new EventHandler(xformEvents.XForm_ControlSetup);


Here's the XFormEvent's XForm_ControlSetup:

 

        public void XForm_ControlSetup(object sender, EventArgs e)
        {
            var control = (XFormControl)sender;

            control.EnableClientScript = true;

            control.BeforeLoadingForm += XForm_BeforeLoadingForm;
            control.ControlsCreated += XForm_ControlsCreated;
            control.BeforeSubmitPostedData += XForm_BeforeSubmitPostedData;
            control.AfterSubmitPostedData += XForm_AfterSubmitPostedData;
        }


Every time the page is accessed, XForm_BeforeLoadingForm and ControlsCreated get hit as should be expected.  However, when you submit the form, you would then expect the BeforeSubmitPostedData and AfterSubmitPostedData to get hit.  I've found a few articles that mention issues with AfterSubmitPostedData never getting executed, but not both of these methods.  Instead, the form seems to be created anew when its submitted and ControlSetup, BeforeLoadingForm, and finally ControlsCreated are executed.  In fact, ControlSetup is executed twice.  This is the case whether the submit button is set to both send an email and save to the DB or just save to the DB.  It's as if every postback is recognized as a new request to the form.

#59887
Jul 03, 2012 20:43
Vote:
 

On your page template with the xform control, are you setting the forms definition in the onload or oninit event? I had the exact same problem this week when setting via onload - If its the same issue I had, moving the code to oninit should solve the problem.

Adam

#59889
Jul 03, 2012 22:12
Vote:
 

By the definition, do you mean the XForm.CreateInstance(new Guid(formGuid));? That occurs within OnInit of a custom control on the page template.

#59987
Jul 09, 2012 21:24
Vote:
 

Yeah.  I moved all my code to the Page Template for simplicity and verified that the forms definition is set in the Page_Init method for the template. BeforeSubmitPostedData never gets hit.

#59988
Jul 09, 2012 23:23
Vote:
 

Can you post the code behind for your template which the form is on. 

#59991
Jul 10, 2012 9:41
Vote:
 

Sure.  Here's the code in the code behind for the template:  

        protected XForm form { get; set; }

        protected void Page_Init(object sender, EventArgs e)
        {
            var formGuid = CurrentPage["XForm"] as string;
            if (!String.IsNullOrEmpty(formGuid))
            {
                form = XForm.CreateInstance(new Guid(formGuid));
                form.PageGuid = CurrentPage.PageGuid;

                FormControl.FormDefinition = form;
            }
        }

#60006
Jul 10, 2012 16:27
Vote:
 

That looks ok to me :/ As a try, here is how Im adding a xform to a page in my web app - 

protected void Page_Init(object sender, EventArgs e)
        {
		    var propertyValue = CurrentPage.Property["XForm"] as PropertyXForm;

            if (propertyValue != null && !propertyValue.IsNull)
            {
                FormControl.FormDefinition = propertyValue.Form;
            }
			
			base.OnInit(e);
        }
#60008
Jul 10, 2012 16:42
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.