Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regarding count down timer in asp.net C# [closed]

Tags:

c#

countdown

I don't have any problem regarding the code, its working fine. But, I am looking for an alternate method for this count down.

Here is the code

CurrentPage.aspx

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    </div>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Label ID="Label2" runat="server" Text="You will be redirected in..."></asp:Label>
            <asp:Timer ID="Timer1" runat="server">
            </asp:Timer>
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <asp:Label ID="Label1" runat="server" Text="10"></asp:Label>
        </ContentTemplate>
    </asp:UpdatePanel>
    </form>
</body>
</html> 

Code behind file

using System;

namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Timer1.Enabled = true;
            Timer1.Interval = 1000;
            Timer1.Tick += new EventHandler<EventArgs>(Timer1_Tick);
        }
        void Timer1_Tick(object sender, EventArgs e)
        {
            int i=(Convert.ToInt16(Label1.Text));
            i = i - 1;
            Label1.Text = i.ToString();
            if (i<0)
            {
                Timer1.Enabled = false;
                Response.Redirect("TargetPage.aspx");
            }
        }
    }
}

All I am looking for is any alternate method.

like image 881
shanu Avatar asked May 21 '26 13:05

shanu


1 Answers

Unless you need to specify redirect location dynamically through c# code, you could implement a purely javascript client side method. It can be a simple javascript function which will cause the window to navigate to desired page.

like image 129
Murtuza Kabul Avatar answered May 23 '26 04:05

Murtuza Kabul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!