Click here to Skip to main content
15,886,720 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have an online exam project. and having some page for question. i was using this cod for question page1
C#
protected void Page_Load(object sender, EventArgs e)
    {
        Label4.Text = Session["us"].ToString();
        if (!SM1.IsInAsyncPostBack)
            Session["timeout"] = DateTime.Now.AddMinutes(1).ToString();
    }


Timer tick event code is :
C#
protected void Timer1_Tick(object sender, EventArgs e)
    {
        DateTime timeout = DateTime.Parse(Session["timeout"].ToString());
        DateTime now = DateTime.Now;
        if (0 > DateTime.Compare(now, timeout))
        {
            TimeSpan ts = timeout - now;
            int mins = ts.Minutes + 60 * ts.Hours; ;
            int secs = ts.Seconds;
            Label5.Text = String.Format("Time remaining:  {0:D2} minutes {1:D2} seconds", mins, secs);
            
        }
    }

but now i wanted to do automatic redirect to second question page2 as will as timer stop. on the other words as first page timer become 0 minutes and 0 second it will redirect to second page
Posted
Updated 7-Oct-21 3:18am
v2

Use Response.Redirect.
Here are some examples - How to: Redirect Users to Another Page[^].

There are other ways to do this - Two approaches to redirection in ASP.NET[^].

Another article on page navigation - Understanding Page Navigation Techniques in ASP.NET[^].

Sometimes though, just a meta tag is sufficient -
http://www.w3schools.com/tags/att_meta_http_equiv.asp[^]
http://www.metatags.info/meta_http_equiv_refresh[^]
Some browsers may not like this tag though.
 
Share this answer
 
I'm assuming you're using an update panel around your timer or else this isn't really going to work;

C#
protected void Timer1_Tick(object sender, EventArgs e)
{

    DateTime timeout = DateTime.Parse(Session["timeout"].ToString());
    DateTime now = DateTime.Now;
    if (0 > DateTime.Compare(now, timeout))
    {
        TimeSpan ts = timeout - now;
        int mins = ts.Minutes + 60 * ts.Hours; ;
        int secs = ts.Seconds;
        Label5.Text = String.Format("Time remaining:  {0:D2} minutes {1:D2} seconds", mins, secs);
    }
    else
    {
        Response.Redirect("target.aspx");
    }
}
 
Share this answer
 
please read my problem first and than advise me .
 
Share this answer
 

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