Hi, I'm new to asp.net, I'm creating a quiz, I have a set of questions that are stored in an array and they are stored in session state, when I load the first page of the quiz a question is randomly chosen with a set of answers. when I move forward a page and then back
I want the same question to be displayed but it keeps displaying a new question, I tried storing the outputted question in session and then loading it before, but it doesn't work any suggestions???
Thanks in advance
namespace Quiz
{
public partial class page2 : System.Web.UI.Page
{
string question;
string[] questions;
string[] answers;
string correctanswer;
public Random rnd = new Random();
protected void Page_Load(object sender, EventArgs e)
{
questions = (string[])Session["Questions"];
int randNum = rnd.Next(questions.Length);
question = questions[randNum];
lblQ1.Text = question;
answers = (string[])Session["answers1"];
correctanswer = answers[1];
for (int i = 0; i < answers.Length; i++)
{
rbAns1.Items[i].Text = answers[i];
}
}
protected void Page_PreRender(object sender, EventArgs e)
{
if (Session["selectedValue1"] != null)
{
rbAns1.SelectedIndex = (int)Session["selectedValue1"];
}
if (Session["questionAsked"] != null)
{
question = Session["questionAsked"].ToString();
lblQ1.Text = question;
}
}
protected void rbAns1_SelectedIndexChanged(object sender, EventArgs e)
{
Session["selectedValue1"] = rbAns1.SelectedIndex;
}
protected void btnPrevious_Click(object sender, EventArgs e)
{
Session["questionAsked"] = question;
Response.Redirect("StartPage.aspx");
}
protected void btnNext_Click(object sender, EventArgs e)
{
Session["questionAsked"] = question;
Response.Redirect("page3.aspx");
}