Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Countdown timer JavaScript(Working fine with Value from drop down list):Timer.js
JavaScript
var tim;
var sec = document.getElementById("ddlTime").value;
function f2()
{
    if (parseInt(sec) > 0)
    {
        sec = parseInt(sec) - 1;
        document.getElementById("lblTimer").innerHTML = "Left Time :" + sec +" Seconds";
        tim = setTimeout("f2()", 1000);
        //return false;
    }
    else
    {
        clearTimeout(tim);
        document.getElementById('btnSubmit').click();
        //return false;
    }
    return false;
}


What I have tried:

ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default1.aspx.cs" Inherits="Default1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><title>Untitled Page <div>
        <asp:Label ID="lblTimer" runat="server" Font-Bold="True" Font-Names="Agency FB" Font-Size="X-Large"
            ForeColor="DarkBlue" Style="z-index: 100; left: 371px; position: absolute; top: 52px"
            Text="TIMER" Width="140px">
        <asp:Button ID="btnStart" runat="server" OnClientClick="return f2();" OnClick="btnStart_Click" Style="z-index: 101;
            left: 365px; position: absolute; top: 127px" Text="Start" />
        <asp:Button ID="btnSubmit" runat="server" Style="z-index: 105; left: 359px; position: absolute;
            top: 264px" Text="Submit" OnClick="btnSubmit_Click" />
        <asp:Label ID="Label1" runat="server" Style="z-index: 103; left: 76px; position: absolute;
            top: 173px" Text="Label">
        <asp:DropDownList ID="ddlTime" runat="server" AutoPostBack="True" Font-Size="Large"
            Style="z-index: 104; left: 279px; position: absolute; top: 51px" Width="61px">
            <asp:listitem>10
            <asp:listitem>180
            <asp:listitem>300
            <asp:listitem>600
           
    </div>


C#
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;

public partial class Default1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void btnStart_Click(object sender, EventArgs e)
    {
        Label1.Text = "Sta!!";
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        lblTimer.Text = "Time Out";
    }
}


I tried this But timer working fine but Server-side work not done on that button click. Please help.
Thank you very much in advance.
Posted
Updated 16-Mar-17 20:20pm
v4
Comments
Prateek Dalbehera 17-Mar-17 1:44am    
Can you please explain your query a bit clearly?
Sunasara Imdadhusen 17-Mar-17 2:32am    
Why you want to start and stop timer from the server? as you haven't any special code so you can do the same using javascript only!
Karthik_Mahalingam 20-Mar-17 3:02am    
Use Improve question to add more info to the question.

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



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