Use to countdown time for use to time limit : in asp.net prograaming

Use to countdown time for use to time limit :



As we know we need many time this type of application ,where we want to some time limit as we thing to make a web site that perform online examination task (online Examination.com),
Then we want to change time at every second and display every time that how many time student have now .here we give some code ,by this you can easily perform this task .
 by this you can easily perform this task .

Use this given div in to <your page name>.aspx page:

<div>
            <asp:ScriptManager ID="SM1" runat="server">
            </asp:ScriptManager>
            <asp:Timer ID="timer1" runat="server" Interval="1000" OnTick="timer1_tick">
            </asp:Timer>
        </div>
        <div>
            <asp:UpdatePanel ID="updPnl" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <asp:Label ID="lblTimer" runat="server" Font-Bold="True" Font-Names="Arial" Font-Size="Large"
                        ForeColor="#6600CC"></asp:Label>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="timer1" EventName="tick" />
                </Triggers>
            </asp:UpdatePanel>
        </div>


Aspx.cs page code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class Admin_Test : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
    {
       
        ScriptManager ScriptManager1 = (ScriptManager)Master.FindControl("ScriptManager1");
     
        if (!ScriptManager1.IsInAsyncPostBack)
           
            Session["timeout"] = DateTime.Now.AddMinutes(60).ToString();

        if (!IsPostBack)
        {
            if (Request.QueryString["OnlineTestID"] != "")
            {
                time1 = System.DateTime.Now;
             
                Fillpaper();
                lblMsg.Text = "";
                lblMsg.Visible = false;

            }
            else
            {
                lblMsg.Text = "Error in loding Paper..";
                lblMsg.Visible = true;
            }
        }
    }

protected void timer1_tick(object sender, EventArgs e)
    {
        if (0 > DateTime.Compare(DateTime.Now, DateTime.Parse(Session["timeout"].ToString())))
        {
            lblTimer.Text = string.Format("Time Left: 00:{0}:{1}", ((Int32)DateTime.Parse(Session["timeout"].ToString()).Subtract(DateTime.Now).TotalMinutes).ToString(), ((Int32)DateTime.Parse(Session["timeout"].ToString()).Subtract(DateTime.Now).Seconds).ToString());
        }
        else
        {
            timer1.Enabled = false;
            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "temp", "<script type='text/javascript'>alert('Time Over.') </script>", false);
            GridView1.Enabled = true;
            GridView1.Visible = false;
        }
    }
}
 

Other Asp.net web Application Related Post:

Comments