whnever i am clciking the next button for next qt to come,countdown strts from begining instead of coninuing from the prvios page. here is my code for aspx file
%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" EnableSessionState="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="cd" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:MultiView ID="MultiView2" runat="server" Visible="true" ActiveViewIndex="0">
<asp:View ID="View1" runat="server">
<table id="question" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2">
<asp:Label ID="lblQuestion" runat="server" Text="Question"></asp:Label></td>
</tr>
<tr>
<td colspan="2" style="height: 19px">
</td>
</tr>
<tr>
<td>
<asp:RadioButton ID="Option1" runat="server" GroupName="gAns" /></td>
<td>
<asp:RadioButton ID="Option2" runat="server" GroupName="gAns" /></td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
<tr>
<td>
<asp:RadioButton ID="Option3" runat="server" GroupName="gAns" /></td>
<td>
<asp:RadioButton ID="Option4" runat="server" GroupName="gAns" /></td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnPrev" runat="server" Text="Previous" OnClick="btnPrev_Click" />
</td>
<td>
<asp:Button ID="btnNext" runat="server" Text="Next" OnClick="btnNext_Click" />
</td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
</table>
<div>
<asp:Label ID="lblMarks" runat="server" Text=""></asp:Label>
</div>
</asp:View>
</asp:MultiView>
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View ID="View2" runat="server">
<asp:Label ID="Label1" runat="server" Text="Time Remaining :"></asp:Label>
<script src="countDown.
js" id="s1" language="javascript" type="text/javascript" ></script>
<asp:TextBox ID="disp" runat="server" Text="10:00"></asp:TextBox>
</asp:View>
</asp:MultiView>
</form>
</body>
</html>
code for aspx.cs file
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
//using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.SessionState;
using System.Net;
//using System.Xml.Linq;
public partial class Default4 : System.Web.UI.Page
{
DataSet ds = new DataSet();
private static int count;
private static int marks;
private static int[] ans = new int[30];
HttpCookie MyCookie = new HttpCookie("LastVisit");
public int Marks
{
set
{
marks = value;
}
get
{
return marks;
}
}
protected void Page_Load(object sender, EventArgs e)
{
//SqlDataSource sds = new SqlDataSource();
//SqlConnection con = new SqlConnection();
//SqlCommand sc = new SqlCommand("select * form question");
string SelectCommand = @"select qno, question, opt1, opt2, opt3, opt4, correct from question where qset=1";
string ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\manisha\My Documents\OnlineExam-ajax\App_Data\OnlineExam.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
SqlDataAdapter sda = new SqlDataAdapter(SelectCommand, ConnectionString);
sda.Fill(ds);
if (!IsPostBack)
{
count = 0; marks = 0;
lblMarks.Text = "(For Testing) Marks = " + Marks.ToString() + " AnsArray = " + ans[0] + ans[1] + ans[2] + ans[3];
foreach (int i in ans)
ans[i] = 0;
PageRefresh();
}
//( Label)(UpdatePanel1.Controls[0]).
//sds.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\WebSite\On lineExam\App_Data\OnlineExam.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
//sds.
}
protected void btnNext_Click(object sender, EventArgs e)
{
MyCookie["Font"] = disp.Text.ToString();
Response.Cookies.Add(MyCookie);
//string result = ds.Tables[0].Rows[count].ItemArray[6].ToString().Trim();
//if(Option1.Checked && Option1.Text.Trim().Equals(result)
// || Option2.Checked && Option2.Text.Trim().Equals(result)
// || Option3.Checked && Option3.Text.Trim().Equals(result)
// || Option4.Checked && Option4.Text.Trim().Equals(result))
//{
// marks += 1;
//disp.Text = MyCookie.Value;
if (Option1.Checked) ans[count] = 1;
if (Option2.Checked) ans[count] = 2;
if (Option3.Checked) ans[count] = 3;
if (Option4.Checked) ans[count] = 4;
CalcMarks();
lblMarks.Text = "(For Testing) Marks = " + Marks.ToString() + " AnsArray = " + ans[0] + ans[1] + ans[2] + ans[3];
if (count < ds.Tables[0].Rows.Count - 1)
count += 1;
PageRefresh();
}
protected void btnPrev_Click(object sender, EventArgs e)
{
//string result = ds.Tables[0].Rows[count].ItemArray[6].ToString().Trim();
if (Option1.Checked) ans[count] = 1;
if (Option2.Checked) ans[count] = 2;
if (Option3.Checked) ans[count] = 3;
if (Option4.Checked) ans[count] = 4;
CalcMarks();
lblMarks.Text = "(For Testing) Marks = " + Marks.ToString() + " AnsArray = " + ans[0] + ans[1] + ans[2] + ans[3];
if (count > 0)
count -= 1;
PageRefresh();
}
protected void PageRefresh()
{
lblQuestion.Text = "Q" + ds.Tables[0].Rows[count].ItemArray[0].ToString().Trim() + ". " + ds.Tables[0].Rows[count].ItemArray[1].ToString().Trim();
Option1.Checked = Option2.Checked = Option3.Checked = Option4.Checked = false;
if (ans[count] == 1) Option1.Checked = true;
if (ans[count] == 2) Option2.Checked = true;
if (ans[count] == 3) Option3.Checked = true;
if (ans[count] == 4) Option4.Checked = true;
Option1.Text = ds.Tables[0].Rows[count].ItemArray[2].ToString().Trim();
Option2.Text = ds.Tables[0].Rows[count].ItemArray[3].ToString().Trim();
Option3.Text = ds.Tables[0].Rows[count].ItemArray[4].ToString().Trim();
Option4.Text = ds.Tables[0].Rows[count].ItemArray[5].ToString().Trim();
}
protected void CalcMarks()
{
int result; int m = 0;
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
result = (int)(ds.Tables[0].Rows[i].ItemArray[6]);
if (ans[i] == result)
{
m += 1;
}
}
Marks = m;
}
protected void Update(object sender, EventArgs e)
{
try
{
// lblTime.Text = DateTime.Now.Second.ToString();
}
catch (Exception ex)
{
}
}
}
plz help me
m@nish@