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);
}
}
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);
}
}