如何在asp.net完成时间后自动移动第二页 [英] how to move second page automatic after the time finish in asp.net

查看:76
本文介绍了如何在asp.net完成时间后自动移动第二页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在线考试项目。并有一些问题的页面。我使用这个鳕鱼问题第1页

<前lang =cs> 受保护 void Page_Load( object sender,EventArgs e)
{
Label4.Text = Session [ us]。ToString();
if (!SM1.IsInAsyncPostBack)
会话[ timeout] = DateTime.Now.AddMinutes( 1 )。ToString();
}





计时器刻度事件代码是

< pre lang =c#> protected void Timer1_Tick( object sender,EventArgs e)
{
DateTime timeout = DateTime.Parse(Session [ 超时]的ToString());
DateTime now = DateTime.Now;
if 0 > DateTime.Compare(现在,超时))
{
TimeSpan ts = timeout - now;
int mins = ts.Minutes + 60 * ts.Hours; ;
int secs = ts.Seconds;
Label5.Text = 字符串 .Format( 剩余时间:{0:D2}分钟{1:D2}秒,分钟,秒);

}
}



但现在我想自动重定向到第二个问题第2页,因为计时器停止。换句话说,当第一页计时器变为0分0秒它将重定向到第二页

解决方案

使用 Response.Redirect

以下是一些例子 - 如何:将用户重定向到另一个页面 [ ^ ]。



还有其他方法可以做到这一点 - 两种在ASP.NET中重定向的方法 [ ^ ]。



关于页面导航的另一篇文章 - 了解页面ASP.NET中的导航技术 [ ^ ]。



有时候,只需一个元标记即可 -

http://www.w3schools.com/tags/att_meta_http_equiv.asp [ ^ ]

http://www.metatags.info/meta_http_equiv_refresh [ ^ ]

有些浏览器可能不喜欢这个标签。


我假设你正在使用计时器周围的更新面板或者这个是不是真的会起作用;



 受保护  void  Timer1_Tick( object  sender,EventArgs e)
{

DateTime timeout = DateTime.Parse(Session [ timeout]。ToString());
DateTime now = DateTime.Now;
if 0 > DateTime.Compare(现在,超时))
{
TimeSpan ts = timeout - now;
int mins = ts.Minutes + 60 * ts.Hours; ;
int secs = ts.Seconds;
Label5.Text = 字符串 .Format( 剩余时间:{0:D2}分钟{1:D2}秒,分钟,秒);
}
else
{
Response.Redirect( target.aspx);
}
}


请先阅读我的问题,然后告诉我。


i have an online exam project. and having some page for question. i was using this cod for question page1

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 :

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

解决方案

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.


I'm assuming you're using an update panel around your timer or else this isn't really going to work;

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");
    }
}


please read my problem first and than advise me .


这篇关于如何在asp.net完成时间后自动移动第二页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆