Dynamic Data Loading


It’s not required to use physical XML files to display the survey in Survey Viewer Web Control. You can simply set the XML definition of the survey direct to the control without providing any file paths. This would be useful in case that you prefer to store the XML file in other storage source like a database.

You don’t have also to store the response XML in a physical path. You can make use of OnResponseRecieved event to get the response XML and store it in the database as well.

This is a sample of dynamic bending for survey XML definition to the Survey Viewer Web Control without using a physical XML file:

private string xml = @"<survey version='1.2'>
                              <meta>
                                <id>sample</id>
                                <title>Sample Survey</title>
                                <description>This is a sample survey description</description>
                                <endtitle>Thank You</endtitle>
                                <enddescription>Thank you for taking this survey</enddescription>
                                <startdate>01/01/0001</startdate>
                                <enddate>12/31/9999</enddate>
                                <quote>2000</quote>
                                <progressbar>true</progressbar>
                              </meta>
                              <pages>
                                <page id='1' title='Start Page' description='This is a sample start page' />
                              </pages>
                              <questions>
                                <question id='1' type='singlechoice' page='1'>
                                  <body>What is your gender?</body>
                                  <remarks>
                                  </remarks>
                                  <footer>
                                  </footer>
                                  <mandatory>false</mandatory>
                                  <otherenabled>false</otherenabled>
                                  <randomized>false</randomized>
                                  <dropdownlist>false</dropdownlist>
                                  <horizontal>false</horizontal>
                                  <choices>
                                    <choice>Male</choice>
                                    <choice>Female</choice>
                                  </choices>
                                  <media />
                                  <rules />
                                </question>
                              </questions>
                            </survey>";

    protected override void OnInit(EventArgs e)
    {
        // Register OnResponseRecieved event of the survey
        this.ucSurveyWebControl.OnResponseRecieved += new
          MentorLogic.Engines.Zodiac.Web.OnResponseRecieved(ucSurveyWebControl_OnResponseRecieved);
        
        base.OnInit(e);
    }

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

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

        //TODO: Save responseXml in your database
    }


See Also