This is a migrated thread and some comments may be shown as answers.

Dynamic Wizard steps

1 Answer 243 Views
Wizard
This is a migrated thread and some comments may be shown as answers.
binny
Top achievements
Rank 1
binny asked on 28 Jan 2015, 03:23 AM
I am trying to create a prototype for online quiz but stuck , can someone help?
My requirement is to create a quiz which will
1) Add the questions / answers dynamically as steps
2) validate the answers and if it is wrong answer add the question back again in the step so that they can retry

And also

I did achieve most of it except that my data and steps are getting mixed, I am sure there is a better way to do it , please help

And also why RadWizard1_WizardStepCreated called everytime there is a change in step

  protected void RadButton1_Click(object sender, EventArgs e)
        {
            //if (RadNumericTextBox1.Value > 0)
            //{
            RadButton button = (RadButton)sender;
            button.Enabled = false;
            List<data> data = new List<data>();
            data = (List<data>)HttpContext.Current.Session["data"];
            for (int i = 0; i < data.Count; i++)
            {
                RadWizardStep step = new RadWizardStep();
                step.ID = "Question"+(i + 1).ToString();                              
                RadWizard1.WizardSteps.Add(step);
            }
            RadWizardStep completeStep = new RadWizardStep();
            completeStep.ID = "Complete";
            RadWizard1.WizardSteps.Add(completeStep);
            RadWizard1.ActiveStepIndex = RadWizard1.WizardSteps[1].Index;
            //}
        }
  protected void RadWizard1_WizardStepCreated(object sender, Telerik.Web.UI.WizardStepCreatedEventArgs e)
        {
            if (e.RadWizardStep.ID == "Complete")
            {
               //complete logic
            }
            else
            {
                List<Data> data = new List<Data>();
                data = (List<Data>)HttpContext.Current.Session["data"];
                Label label = new Label();
                RadioButtonList list = new RadioButtonList();
                list.AutoPostBack = true;
                list.CausesValidation = true;
                list.SelectedIndexChanged += new EventHandler(list_SelectedIndexChanged);
              
                label.Text = data[e.RadWizardStep.Index - 1].Question;                     
                list.Items.Add(data[e.RadWizardStep.Index - 1].A);
                list.Items.Add(data[e.RadWizardStep.Index - 1].B);
                list.Items.Add(data[e.RadWizardStep.Index - 1].C);
              
                e.RadWizardStep.Controls.Add(label);
                e.RadWizardStep.Controls.Add(new Literal() { Text = "<br />" });
                e.RadWizardStep.Controls.Add(list);
                }
                  
                }          
           
        }
  private void list_SelectedIndexChanged(object sender, EventArgs e)
        {
            RadioButtonList RBL = (RadioButtonList)sender;
            List<data> data = new List<data>();
            data wrongAnswer = new data();
            data = (List<data>)HttpContext.Current.Session["data"];
            string s = RBL.SelectedValue.ToString();
            string y =  data[RadWizard1.ActiveStepIndex-1].Answer;
            if(s.Trim() == y.Trim())
            {
               some logic
            }
            else
            {
                some logic  


List<data> ldata= new List<data>();
data.Add(listQuizData[RadWizard1.ActiveStepIndex - 1]);
HttpContext.Current.Session["data"] = ldata; 
         
RadWizardStep step = new RadWizardStep();
step.ID = " Repeat Question";
RadWizard1.WizardSteps.Add(step);
            }
          
          
         
        }

1 Answer, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 01 Feb 2015, 08:40 PM
Hello,

I would like to say that your idea and implementation seems absolutely correct. A possible reason for mixing questions(data) and steps might be the following code:
//code behind
label.Text = data[e.RadWizardStep.Index - 1].Question;                    
list.Items.Add(data[e.RadWizardStep.Index - 1].A);
 list.Items.Add(data[e.RadWizardStep.Index - 1].B);
list.Items.Add(data[e.RadWizardStep.Index - 1].C);

Perhaps you can access the same index in the "data" collection as the step index ( not to subtract "1" from the e.WizardStep.Index). I believe such logic might lead to unexpected behavior.

As for second question - the WizardStepCreated event is fired whe a step is changed in order to persist  the controls within the steps. All dynamically created steps should be recreated on the server each time.


Regards,
Boyan Dimitrov
Telerik
Tags
Wizard
Asked by
binny
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Share this question
or