Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Asp.Net Ajax timer issue

$
0
0

Hi,

I am Ashok Kumar,I have created an online exam website where i want to implement ajax timer. I have written the code but the problem is I am initializing a session with adding no of seconds for the timer suppose 10 secs. and when the page loads it shows from 6 seconds. So i feel when the page prerender completes the timer has laready started thats why it shows from 6 seconds instead of 10 sec

This is the code. If any body can suggest how to display from 10 secs will be greatful.

This is the aspx file code

<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
    
        </asp:ScriptManager>
      
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick">
            </asp:Timer>
               <asp:Label ID="Label1" runat="server" Text="Remaining Time :"></asp:Label>&nbsp;<asp:Label ID="lblTime" runat="server" Text=""></asp:Label>
        </ContentTemplate>
        </asp:UpdatePanel>       
    </div>
    </form>

</body>

This the cs file code

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Session["time"] = DateTime.Now.AddSeconds(10);
        }
    }

  

    protected void Timer1_Tick(object sender, EventArgs e)
    {
        if (lblTime.Text != "TimeOut!")
        {
            TimeSpan time1 = new TimeSpan();
            time1 = (DateTime)Session["time"] - DateTime.Now;
            if (time1.Seconds <= 0)
            {
                lblTime.Text = "TimeOut!";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "StartUpScript1", "alert('hello')", true);

            }
            else
            {
                lblTime.Text = time1.Hours.ToString("#00") + ":" + time1.Minutes.ToString("#00") + ":" + time1.Seconds.ToString("#00");
            }
        }
        else
        {
            //Timer1.Interval = 0;
        }
    }

 

Thanks In Advance.

Ashok Kumar.


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>