110,534
社区成员
发帖
与我相关
我的任务
分享
System.Timers.Timer t = new System.Timers.Timer();//实例化Timer类
int intTime = 5000;
t.Interval = intTime;//设置间隔时间,为毫秒;
t.Elapsed += new System.Timers.ElapsedEventHandler(theout);//到达时间的时候执行事件;
t.AutoReset = false;//设置是执行一次(false)还是一直执行(true);
t.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件;
public void theout(object source, System.Timers.ElapsedEventArgs e)
{
//Response.Redirect("Entry.aspx");
//Server.Transfer("Entry.aspx",true);
//Response.Write("<meta http-equiv=refresh content= '5;URL=Entry.aspx '> ");
//Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "redirect", "<script type='text/javascript'>test();</script>");
}
//Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "redirect", "<script type='text/javascript'>test()</script>");
是我使用的前台方法跳转,可惜还是不行
这里是后台写的:
//Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "redirect", "<script type='text/javascript'>window.location.href = 'Entry.aspx';</script>");
<script type="text/javascript">
function redirect() {
window.location.href="xxx";
}
</script>
后台:
int timeout = 5000;
Page.ClientScript.RegisterStartupScript(this.GetType(), "redirect", string.Format("<script type='text/javascript'>window.setTimeout(redirect, {0});</script>",timeout));
没测试过,不知道有没有什么地方拼写错误什么的,但原理不会错。