Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7032153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:53:51+00:00 2026-05-28T00:53:51+00:00

The web application that I am developing right now has something called quiz engine

  • 0

The web application that I am developing right now has something called quiz engine which provides users with short quizzes which consist of one question or more. Now, I have a problem with taking/ answering the quiz:
When the user finishes the quiz and he goes to the Result Page and he goes back to the Quiz page and answers the same question, he will get two results and I don’t know why !!!

In brief, answering same question multiple times should not create multiple entries.

For creating the Quiz engine, I used the Toturial for the Quiz Engine in the ASP.NET website for creating what I have.

My Code-Behind:

This is the code that is responsible for saving the answers:

protected void nextButton_Click(object sender, EventArgs e)
    {
        // Save off previous answers
        System.Data.DataRowView dr = (System.Data.DataRowView)questionDetails.DataItem;

        // Create Answer object to save values
        Answer a = new Answer();
        a.QuestionID = dr["QuestionOrder"].ToString();
        a.CorrectAnswer = dr["CorrectAnswer"].ToString();
        a.UserAnswer = answerDropDownList.SelectedValue.ToString();

        ArrayList al = (ArrayList)Session["AnswerList"];
        al.Add(a);

        Session.Add("AnswerList", al);

        if (questionDetails.PageIndex == questionDetails.PageCount - 1)
        {
            // Go to evaluate answers
            Response.Redirect("Results.aspx");
        }
        else
        {
            questionDetails.PageIndex++;
        }

        if (questionDetails.PageIndex == questionDetails.PageCount - 1)
        {
            nextButton.Text = "Finished";
        }

    }

So now how I can let the user be able to change his answer (or goes back to one of the answered questions) and this new answer will replace the previous one (not to be considered that the user answered the same question twice). How to do that?

EDIT:

The following code is responsible for saving the result:

resultGrid.DataSource = al;
        resultGrid.DataBind();

        // Save the results into the database.
        if (IsPostBack == false)
        {
            // Calculate score
            double questions = al.Count;
            double correct = 0.0;


            for (int i = 0; i < al.Count; i++)
            {
                Answer a = (Answer)al[i];
                if (a.Result == Answer.ResultValue.Correct)
                    correct++;
            }

            double score = (correct / questions) * 100;
            string username = HttpContext.Current.User.Identity.Name.ToString().Replace("ARAMCO\\", "");
            SqlDataSource userQuizDataSource = new SqlDataSource();
            userQuizDataSource.ConnectionString = ConfigurationManager.ConnectionStrings["testConnectionString"].ToString();
            userQuizDataSource.InsertCommand = "INSERT INTO [UserQuiz] ([QuizID], [DateTimeComplete], [Score], [Username]) VALUES (@QuizID, @DateTimeComplete, @Score, @Username)";

            userQuizDataSource.InsertParameters.Add("QuizID", Session["QuizID"].ToString());
            userQuizDataSource.InsertParameters.Add("DateTimeComplete", DateTime.Now.ToString());
            userQuizDataSource.InsertParameters.Add("Score", score.ToString());
            userQuizDataSource.InsertParameters.Add("Username", username);

            int rowsAffected = userQuizDataSource.Insert();
            if (rowsAffected == 0)
            {
                // Let's just notify that the insertion didn't
                // work, but let' s continue on ...
                errorLabel.Text = "There was a problem saving your quiz results into our database.  Therefore, the results from this quiz will not be displayed on the list on the main menu.";


            }

        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:53:52+00:00Added an answer on May 28, 2026 at 12:53 am

    Here what can you try

    Before you add answer to AnswerList, check if that question already exists in the list, if yes replace that with the current. This you will have to do when you are saving the answer to DB. The code below will update the object in Session only.

     // Create Answer object to save values
     Answer a = new Answer();
     a.QuestionID = dr["QuestionOrder"].ToString();
     a.CorrectAnswer = dr["CorrectAnswer"].ToString();
     a.UserAnswer = answerDropDownList.SelectedValue.ToString();
    
     ArrayList al = (ArrayList)Session["AnswerList"];
     var oldAnswer = al.ToArray().Where(ans => (ans as Answer).QuestionID == a.QuestionID);
     if (oldAnswer.Count() != 0)
     {
          a = oldAnswer.FirstOrDefault() as Answer;
          a.CorrectAnswer = dr["CorrectAnswer"].ToString();
          a.UserAnswer = answerDropDownList.SelectedValue.ToString();
     }
     else
     {
          al.Add(a);
     }
    
     //Rest of your code
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The web application that I am developing right now has something called quiz engine
The web application that I am developing right now has something called quiz engine
Right now I'm developing the prototype of a web application that aggregates large number
I'm developing a Web application that will let users upload images. My concern is
I'm developing a web application that has to support lots of simultaneous requests, and
I am developing a web application for a comapny. This application provides the users
Right now, I’m working on a legacy web application that is made up of
We are developing and web application which allows users to register for certain events.
I a web application that I am developing (being developed in PHP) when a
I'm using JQuery and Prototype in this web application that I'm developing. I'm looking

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.