示例#1
0
        //protected void Page_Init(object sender, EventArgs e) //Trying to get submit button to accept the submitBtn_Click event unsuccessfully
        //{
        //    Button submit = new Button();
        //    submit.Text = "Submit Evaluation";
        //    submit.CssClass = "btn btn-warning";
        //    submit.ID = "submitBtn";
        //    submit.Click += new EventHandler(submitBtn_Click);
        //    testForm.Controls.AddAt(testForm.Controls.Count, submit); //Sets it at the bottom of the form
        //}

        protected void getQuestionsBtn_Click(object sender, EventArgs e)
        {
            List <Question> type1;
            List <Question> type2;
            List <Question> allQuestions;

            evaluation = new Evaluation(int.Parse(questionSelect.SelectedItem.Value), questionSelect.SelectedItem.Text,
                                        Convert.ToDateTime("01/01/2016"), Convert.ToDateTime("01/02/2016"));
            Session["evaluation"] = evaluation;
            allQuestions          = evaluation.GetQuestions();
            type1 = allQuestions.Where(q => q.QType == 1).ToList();
            type2 = allQuestions.Where(q => q.QType == 2).ToList();

            //Dynamically creating controls and adding them to the form
            for (int i = 0; i < type1.Count; i++)
            {
                qType1 c1 = (qType1)LoadControl("~/qType1.ascx");
                c1.ID = "q1" + i;
                testForm.Controls.AddAt(testForm.Controls.Count - 2, c1);
                //RequiredFieldValidator q1req = new RequiredFieldValidator(); //couldn't get this to work. Seemed like it wanted to validate before I had a chance to answer
                //q1req.ID = "RequiredFieldValidator1" + i;
                //q1req.ControlToValidate = c1.ID;
                //q1req.ErrorMessage = "Please select an answer";
                //q1req.SetFocusOnError = true;
                //q1req.CssClass = "text-danger";
                //q1req.Runat = "server";
                //testForm.Controls.AddAt(testForm.Controls.Count - 2, q1req);

                if (i == type1.Count - 1)
                {
                    for (int y = 0; y < type2.Count; y++)
                    {
                        qType2 c2 = (qType2)LoadControl("~/qType2.ascx");
                        c2.ID = "q2" + y;
                        testForm.Controls.AddAt(testForm.Controls.Count - 2, c2);
                        //RequiredFieldValidator q2req = new RequiredFieldValidator();
                        //q2req.ID = "RequiredFieldValidator2" + y;
                        //q2req.ControlToValidate = c2.ID;
                        //q2req.ErrorMessage = "Please select an answer";
                        //q2req.SetFocusOnError = true;
                        //q2req.CssClass = "text-danger";
                        //q2req.Runat = "server";
                        //testForm.Controls.AddAt(testForm.Controls.Count - 2, q2req);
                    }
                    //CreateSubmitButton();
                    submitBtn.Visible = true;
                }
            }
            SetType1Questions(type1);
            SetType2Questions(type2);
            Session["form"] = testForm;
        }
示例#2
0
        //Setting the question text for Type 2 questions
        private void SetType2Questions(List <Question> type2)
        {
            int x = 0;

            foreach (Question qt2 in type2)
            {
                qType2 q = (qType2)testForm.FindControl("q2" + x);
                q.SetQuestionText(qt2.Text);
                q.QuestionID = qt2.ID;
                x++;
                if (x == type2.Count)
                {
                    x = 0;
                    break;
                }
            }
        }