November Happy Hour will be moved to Thursday December 5th.

Check if a user has submitted an XForm

Vote:
 
Hi! How can I check if current user has submitted an XForm in Page_Load event? I wan't to show the statistics control instead of the XForm when the user aleady has answered a question. /Jonas
#13109
Jul 04, 2007 14:28
Vote:
 
Hi Jonas! You could use the XFormData's HasAlreadyPosted method. Something like this in the pagetemplate code: protected void override OnInit(EventArgs ea) { if( myXFormControl.Data.HasAlreadyPosted( this )) { // switch to statistics view } } Regards, Johan Olofsson EPiServer AB
#15430
Jul 04, 2007 15:14
Vote:
 
When i try this, XFormControl is always null in OnInit event. Code in front (user control): Code behind: override protected void OnInit(EventArgs e) { PropertyXForm form = XFormProperty.InnerProperty as PropertyXForm; if (form.XFormControl.Data.HasAlreadyPosted(this.Page))
#15431
Jul 06, 2007 8:15
Vote:
 
Hi Jonas! The problem is that the contained XFormControl wont be available until CreateChildControls() has been called. But, there is another way of getting the XFormData, you could use an explicit call to CreateFormData(). Note, that in order for HasAlreadPosted() to work, you must specify the ChannelOption.DataBase first. This would normally be done on the Submit button click. Check out the below code, it should work in the OnInit(): EPiServer.Core.PropertyXForm propXForm = XFormProperty.InnerProperty as EPiServer.Core.PropertyXForm; EPiServer.XForms.XFormData formData = propXForm.Form.CreateFormData(); formData.ChannelOptions = EPiServer.XForms.ChannelOptions.Database; if(formData.HasAlreadyPosted( this.Page )) { Response.Write( "already voted" ); } Regards, Johan Olofsson EPiServer AB
#15432
Jul 06, 2007 14:04
* 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.