Dynamic Data Loading


You can bind the XML definition of the survey direct to the Survey Builder Web Control without the need to use physical XML files or even storing the survey in your physical desk. The web control can bind the XML on the fly and load the survey pages, questions, branching rules and media files in the web page without using any physical files.

The sample below bind the survey XML from a local variable and bind the web control.


    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 OnSaveSurvey event
        this.ucSurveyBuilderWebControl.OnSaveSurvey += new 
MentorLogic.Engines.Zodiac.Web.OnSaveSurvey(ucSurveyBuilderWebControl_OnSaveSurvey);

        base.OnInit(e);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            // Set the XML definition of the survey. This XML can be retrieved from the database.
            this.ucSurveyBuilderWebControl.Xml = xml;           
        }
    }

    protected void ucSurveyBuilderWebControl_OnSaveSurvey(object sender, SurveyArgs args)
    {
        // Receive the new XML definition of the survey after save
        string surveyXml = args.Xml;

        // TODO: surveyXml string to be saved on the database
    }