Save and Continue Feature


Sometimes you will need to provide your users the ability to save their surveys and continue it in a later time. ZSURVEY Survey Viewer Web Control provides you with the ability to provide this feature to your user.

1. You need to set EnableSaveAndContinue property to true.

<Zodiac:SurveyViewerWebControl ID="ucSurveyWebControl" 
                               CssClass="bluesky"                                
                               OutputFolder="Responses"
                               MediaUploadPath="Uploads"
                               EnableSaveContinueLater="true"
                               AuthType="None"                                                                           
                               runat="server">
</Zodiac:SurveyViewerWebControl>


2. You will need to track if the user has already taken or partially answered the survey before using a session or cookie variable. In Page Load, check if the session or cookie has a value. If there is a value, then bind the partial response of the user to the web control.

The web control will auto load the response of the user to the web control and set the current active survey page to the last page the user was stopping at.

protected void Page_Load(object sender, EventArgs e)
{
        if (!IsPostBack)
        {
            // Set the XML definition of the survey
            this.ucSurveyWebControl.Xml = xml;
            this.ucSurveyWebControl.DataBind();

            if (Session["ZD_SURVEY_RESPONSE_ID"] != null)
            {
                var respXml = ( from c in context.SurveyResponses
                                where c.ID == int.Parse(Session["ZD_SURVEY_RESPONSE_ID"].ToString())
                                select c.ResponseXML).First();

                this.ucSurveyWebControl.AssociatedResponseXml = respXml;
            }

            this.ucSurveyWebControl.DataBind();
        }
}


3. The OnResponseReceived event will fire in two cases: when the user click on Save and Continue button and when the user finish the survey. The event should get the response either a partial response or complete response and save it to the database or any storage repository.

You need also to set the session or cookie variable for the user response to be able to fetch it when the user will decide to continue the survey in a later time.

protected void ucSurveyWebControl_OnResponseRecieved(object sender, SurveyResponseArgs args)
{
        // Recieve the XML definition of the response
        string responseXml = args.Xml;

        SurveyResponse resp = XmlSurveyResponseRepository.DeserializeResponse(responseXml);

        context.SurveyResponses.InsertOnSubmit(resp);        
        context.SubmitChanges();
                
        Session["ZD_SURVEY_RESPONSE_ID"] = resp.ID;
               
}

See Also