考试结束后没有得到正确的结果 [英] Not getting right result on completion of exam

查看:87
本文介绍了考试结束后没有得到正确的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做在线考试系统的项目。在onlineexam.aspx页面中遇到问题,问题将显示给候选人,但问题是在完成考试后结果值正在改变但没有按预期得到正确的输出。



OnlineExam.aspx



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

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

推荐答案

在页面加载事件中

添加代码



if(!page.ispostback)

{

//这里你的代码

}
In Page Load Event
add the code under

if(!page.ispostback)
{
//Your code here
}


这篇关于考试结束后没有得到正确的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆