SurveyFile and Answerfile setted in Page_Init are still ignored

Developer
Jun 8, 2008 at 1:32 PM
Edited Jun 8, 2008 at 11:51 PM
Hi,
We use your latest version (2.7) of WebSurvey Control. I want to set dynamically answer and survey file. Our idea is to get xml that define survey from database, than generate file for survey control and after survey would be done send them to back to db. Because of this, we use user control which should be act as survey viewer and done all job to get, generate, show and send back.  I have same issues with this.

a) Do I need to set default Answer and Survey file although I use dynamically set paths to file in Page_Init event handler ?
b) I set these paths (as I mentioned before) dynamically in Page_Init.

See Example:

*.ascx file

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PatientTestViewer.ascx.cs" Inherits="sebb4g2SS08.Memory.MemoryWeb.User_Controls.PatientTestViewer" %>
    <%@ Register Assembly="sstchur.web.survey" Namespace="sstchur.web.survey" TagPrefix="sstchur" %>
    <asp:UpdatePanel ID="UpdatePanelWebSurvey" runat="server">
        <ContentTemplate>
            <sstchur:WebSurvey ID="WebSurveyPatientTest" runat="server" AnswersFile="~/App_Data/_temp/answers.xml"
            SurveyFile="~/App_Data/_temp/survey.xml" />
        </ContentTemplate>
    </asp:UpdatePanel>


*.ascx.cs file

        /// <summary>
        /// Event handler for page being initalized.
        /// </summary>
        /// <param name="sender">Publisher of event handler.</param>
        /// <param name="e">Parameters for event handler sended by publisher.</param>
        protected void Page_Init(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {

                if (_currentAction == PatientTestViewerMode.preview)
                {
                    _surveyFile = SurveyFileHandler.CreatePreviewUniqueFileFromXML(Server.MapPath("~"), _testID);
                    _answerFile = SurveyFileHandler.CreateUniqueFileDescriptorForPreview(Server.MapPath("~"), _testID);
                }
                else
                {
                    //TODO: Implement if not preview
                }

                WebSurveyPatientTest.SurveyFile = _surveyFile;
                WebSurveyPatientTest.AnswersFile = _answerFile;
            }
        }

But these generated files are still ignored. Do you have a idea why?

Regards
Anton Kalcik

UPDATE: Ok I still used your TestHarness project which is applied by source code, to be sure if is not some issue in our code.

        public void Page_Init(Object sender, EventArgs e)
        {
            // programatically set the .SurveyFile and/or .AnswersFile here (if desired)
            //ws.SurveyFile = "colors.xml";
            //ws.AnswersFile = "colors_answers.xml";
        }
       

I uncommented ws.SurveyFile = "colors.xml", but nothing happened!
Developer
Jun 9, 2008 at 8:44 AM
Any idea somebody?
Developer
Jun 9, 2008 at 8:34 PM
Hello sstchur!
Please can you give me a hint if is this issue in your code, or we do something wrong? We have no idea, how to use this control at the way I described above.

Thanks
AKa
Developer
Jun 10, 2008 at 12:38 PM
Edited Jun 10, 2008 at 12:50 PM
Hi Steve,
I took your control under the magnifier with reflector (because it seems last posted source code isn't the same as in last version of websurvey implemented is). If I use Page_Init event handler to set survey and answer data as you mentioned nothing happens. I think is to late, to do this, because at this time is your control loaded.

See picture from stack.

My idea was to implement Init event handler for your control (If it isn't still late !?) . But this event would be never thrown. I think reason is, because in your code is missing to call event handler from class you inherited (WebControl).

This code is from reflector:

protected override void OnInit(EventArgs e)
{
string filename = HttpContext.Current.Server.MapPath(this.m_strSurveyFile);
this.m_strAnswersFile = HttpContext.Current.Server.MapPath(this.m_strAnswersFile);
XmlDocument document = new XmlDocument();
document.Load(filename);
XmlElement documentElement = document.DocumentElement;
XmlAttribute attribute = documentElement.Attributes["allowrepeats"];
if (attribute != null)
{
this.m_bAllowRepeats = attribute.Value != "false";
}
XmlAttribute attribute2 = documentElement.Attributes["redirecturl"];
if (attribute2 != null)
{
this.m_strRedirectUrl = attribute2.Value;
}
XmlAttribute attribute3 = documentElement.Attributes["cookiename"];
if (attribute3 != null)
{
this.m_strCookieName = attribute3.Value;
}
XmlNode node = documentElement.SelectSingleNode("//WebSurvey/EmailResults");
if (node != null)
{
this.m_strEmailTo = node.SelectSingleNode("EmailTo").InnerText;
this.m_strSmtpServer = node.SelectSingleNode("SmtpServer").InnerText;
}
XmlNodeList list = documentElement.SelectNodes("//WebSurvey/Group");
this.CreateWebSurveyControls(list);
((Panel) this.m_panels[0]).Visible = true;
}


I can't see base.OnInit(e) method. So correct code should be looks like this I think:

protected override void OnInit(EventArgs e)
{
base.OnInit(e) //this should raise a event Init!
string filename = HttpContext.Current.Server.MapPath(this.m_strSurveyFile);
this.m_strAnswersFile = HttpContext.Current.Server.MapPath(this.m_strAnswersFile);
XmlDocument document = new XmlDocument();
document.Load(filename);
XmlElement documentElement = document.DocumentElement;
XmlAttribute attribute = documentElement.Attributes["allowrepeats"];
if (attribute != null)
{
this.m_bAllowRepeats = attribute.Value != "false";
}
XmlAttribute attribute2 = documentElement.Attributes["redirecturl"];
if (attribute2 != null)
{
this.m_strRedirectUrl = attribute2.Value;
}
XmlAttribute attribute3 = documentElement.Attributes["cookiename"];
if (attribute3 != null)
{
this.m_strCookieName = attribute3.Value;
}
XmlNode node = documentElement.SelectSingleNode("//WebSurvey/EmailResults");
if (node != null)
{
this.m_strEmailTo = node.SelectSingleNode("EmailTo").InnerText;
this.m_strSmtpServer = node.SelectSingleNode("SmtpServer").InnerText;
}
XmlNodeList list = documentElement.SelectNodes("//WebSurvey/Group");
this.CreateWebSurveyControls(list);
((Panel) this.m_panels[0]).Visible = true;
}

Regards
AKa
Coordinator
Jun 12, 2008 at 1:39 AM
Aka,

You might be right about this.  I will take a look as soon as I get a chance.  It's possible that I accidentally checked in old source code last time.

Also, the CodePlex site has been having some issue (which I contacted them about) whereby certain files in the ZIP are showing up as 0 byte files.

You might want to try the TestHarness from the previous check in.  I /know/ there was a point at which it was indeed working.
Coordinator
Jun 12, 2008 at 2:14 AM
Ok, I just tried the TestHarness locally and setting the Survey and/or AnswersFile programmatically in Page_Init is definitely working.

Maybe the code isn't getting checked in correctly or something, but I would suggest giving the TestHarness another try.  All I did was uncomment the commented lines and pushed F5.  I saw the Colors survey get loaded instead, so it definitely worked.
Developer
Jun 22, 2008 at 10:48 AM
Hi Steve,
sorry that my response is too late. With version 2.7.0.1 seems to be to be fixed this issue.
Thank you
AKa