1

I have a code and an array inside like this one :

using System;

public partial class bug : System.Web.UI.Page
{

double[] Score = new double[10];
protected void Page_Load(object sender, EventArgs e)
{

 load the form with questions from database (but show only one)
}
 protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
 {
  when this clicked, evaluate the answer from TextBox1 and write the score to Score[questionnumber].
 }
 protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
 {
  go to the question of the clicked Hyperlink's number.
 }

}

So, what happens is, I open this website, I see there first question, I put my answer and submit it, then it returns the score of my first question, after that I click 2nd question's hyperlink, and form takes me to my 2nd question, here is the problem happens, I don't know why but the array (Score array) gets resetted here, so when I submit my answer for 2nd question, it puts the answer to Score[0] instead of putting it to the index of the number of question number. maybe it re-initialize again because of that. So, What should I do to keep not happening it being resetted? Please help, I really need it.

Cem Sultan
  • 79
  • 1
  • 13

1 Answers1

1

Here is the answer I finally found:

if (!IsPostBack)
    {

        int sum = new deney().Database();
        Score = new double[sum];
        Session["myScore"] = Score;
    }

    Score = (double[])Session["myScore"];

Basically, placing the score array into the session, and getting it back every form submit. Thanks to Lasse v. Karlsen, he provided this answer to me in chat platform. I believe if chat option didn't require so much reputation, we won't see so many questions opened every day, plus Stackoverflow would be better this way I guess. A Million Thanks to everybody, especially Lasse v. Karlsen

Lasse v. Karlsen original answer on Chat Platform

Cem Sultan
  • 79
  • 1
  • 13
  • Even though for a week, I have tried this option, I found out that this way of solving this issue made my website very slow. There were only 32 items in array, and about 8-10 people were using the website at the same time, I guess this is not a good solution at the end. Therefore, I switched to Database option, now adding all scores inside database, then collecting them all together and getting final result. The second way also taught me using IF statements inside mysql queries, which are awesome. I am glad I did this switch, it is really amazing to learn new things everyday :) – Cem Sultan Apr 12 '17 at 16:01