Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm doing project on online exam system. Getting problem in onlineexam.aspx page where the question will b displayed to the candidate but problem is that after completion of exam the result value is changing but not getting proper output as expected.

OnlineExam.aspx

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Security;
using System.Data;

public partial class OnlineExam : System.Web.UI.Page
{
    
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["result"] == null)
        {
            Session["result"] = '0';
        }
        Result.Text = Session["result"].ToString();
 
        if (Session["Number"] == null)
        {
            Session["Number"] = 1;
        }
        
        Q.Text = Session["Number"].ToString();

        con.Open();
        SqlCommand cmd = new SqlCommand("Select * from Questions where QuestionNo = '" + Q.Text + "'",con);
        SqlDataReader dr = cmd.ExecuteReader();
        if (dr.Read())
        {
            Questions.Text = dr["Question"].ToString();
            Option1_lbl.Text = dr["Ans1"].ToString();
            Option2_lbl.Text = dr["Ans2"].ToString();
            Option3_lbl.Text = dr["Ans3"].ToString();
            Option4_lbl.Text = dr["Ans4"].ToString();
        }
        con.Close();

        con.Open();
        SqlCommand cmd1 = new SqlCommand("Select * from Answers where QuestionNo = '" + Q.Text + "'",con);
        SqlDataReader dr1 = cmd1.ExecuteReader();
        if (dr1.Read())
        {
            Answer.Text = dr1["Answer"].ToString();
        }
        con.Close();   
    }

    protected void Option1_rb_CheckedChanged(object sender, EventArgs e)
    {
        if (Option1_rb.Checked)
        {
            OptionAns.Text = Option1_lbl.Text;
        }
    }
    protected void Option2_rb_CheckedChanged(object sender, EventArgs e)
    {
        if (Option2_rb.Checked)
        {
            OptionAns.Text = Option2_lbl.Text;
        }
    }
    protected void Option3_rb_CheckedChanged(object sender, EventArgs e)
    {
        if (Option3_rb.Checked)
        {
            OptionAns.Text = Option3_lbl.Text;
        }
    }
    protected void Option4_rb_CheckedChanged(object sender, EventArgs e)
    {
        if (Option4_rb.Checked)
        {
            OptionAns.Text = Option4_lbl.Text;
        }
    }
    protected void Next_btn_Click(object sender, EventArgs e)
    {
        int i=0;
        if (Session["Number"] == null)
        {
            Session["Number"] = '0';
        }
        else
        {
            i = int.Parse(Session["Number"].ToString());
        }
        if (OptionAns.Text==Answer.Text)
        {
            int res;
            res = int.Parse(Session["result"].ToString()) + 1;
            Session["result"] = res;
        }
        if (i <= 5)
        {
            Session["Number"] = ++i; 
            
        }
        else
        {
            Response.Redirect("Result.aspx");
        }
    }
}
Posted
Updated 28-Feb-14 23:21pm
v2
Comments
Ank001 1-Mar-14 4:27am    
someone please help me out to solve this problem.
Richard MacCutchan 1-Mar-14 4:35am    
What problem, you have not explained what is wrong.

1 solution

In Page Load Event
add the code under

if(!page.ispostback)
{
//Your code here
}
 
Share this answer
 
Comments
Ank001 1-Mar-14 22:33pm    
It is not working.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900