Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 12th, 2008, 03:34 AM
Registered User
 
Join Date: Sep 2008
Location: kolkata, west bengal, India.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default countdown timer for online exam project-help me

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>
        &nbsp;&nbsp;


        <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">
                    &nbsp;</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">
                    &nbsp;</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">
                    &nbsp;</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">
                    &nbsp;</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@
Reply With Quote
  #2 (permalink)  
Old September 12th, 2008, 03:56 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hampshire, United Kingdom.
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

So, you have pasted all that code, crying for help and failed to copy the code that actually matters (the countdown script).
Also, where are you displaying the time? Label1? lblTime? Neither seem to be getting updated.

I could hazard a good guess purely based on the problem description. You are not persisting your "time remaining" to the correct place, its being reset on each page load.

Rob
http://cantgrokwontgrok.blogspot.com
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
online exam project manisha agarwal ASP.NET 2.0 Basics 1 September 2nd, 2008 11:07 AM
Countdown timer DennyLoi Javascript How-To 2 November 27th, 2007 08:01 AM
Countdown Timer stalkingbutler Access VBA 2 April 16th, 2007 11:44 AM
Countdown timer ashik112 Classic ASP Basics 1 February 25th, 2007 07:09 PM
Countdown Timer loveperson Beginning VB 6 1 January 7th, 2005 05:31 PM



All times are GMT -4. The time now is 11:50 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.