自动刷新ASP.NET网页定义的时间间隔后? [英] Auto refresh ASP.NET web page after defined interval?

查看:193
本文介绍了自动刷新ASP.NET网页定义的时间间隔后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网站之一,我需要15分钟后实现网页自动刷新。

有关这个才达到我有以下code线写

 < META HTTP-当量=刷新内容=60; URL =/>

但我现在面临一个问题,经过15分钟页面的这个时间会刷新一个新的页面加载。

在我的网页我已经使用具有城市名单的组合框,还有一种情况,当我在索引3从此列表中选择一个项目后,我只是做页面闲置和后15分页与剧本我写刷新自动回发(上述)。但问题是,由于这个页面重新加载一个新的一页,code里面的(!回传)执行哪个笔芯组合框,并在索引1

请帮我解决这个问题?

我的基本要求是,每当用户到达该页面,并使其闲置时间较长,会议不应该过期,因此我写上面的脚本,使会议将是活的。


解决方案

下面是一个不错的javascript把戏保持会话活着 - 而不是刷新整个页面

 < IMG ID =keepAliveIMGWIDTH =1HEIGHT =1SRC =?/ IMG / UI / spacer.gif的 />< SCRIPT LANGUAGE =JavaScript的类型=文/ JavaScript的>
    变种myImg =的document.getElementById(keepAliveIMG);    如果(myImg){
        window.setInterval(函数(){
              myImg.src = myImg.src.replace(/\\?.*$/ +的Math.random()'?');
            },6000);
    }
< / SCRIPT>

(只要你喜欢改变定时器的时间 - 现在是6秒)

类似的帖子:<一href=\"http://stackoverflow.com/questions/3308918/what-is-the-best-approach-to-handle-session-timeouts-in-asp-net/3309046#3309046\">http://stackoverflow.com/questions/3308918/what-is-the-best-approach-to-handle-session-timeouts-in-asp-net/3309046#3309046

In one of my website, i required to implement automatic refresh of webpage after 15 minute.

For this to achive i have write following line of code

<meta http-equiv="refresh" content="60;url=" />

But i am facing one problem that after this duration of 15minute page will refresh as a new page load.

At my page i have used combo box having city list, there is a case when i select an item from this list at index 3. After that i just make page idle and after 15 minute page is refresh with the script i write for auto post back (mentioned above). But the problem is that due to this page is reload as a new page and code inside (!PostBack) execute which refill combobox and reset at index 1.

Please help me to solve this problem?

My basic requirement is that whenever user reaches that page and makes it idle for longer time, session should not expire and hence i am writing above script so that session would be live.

解决方案

Here is a nice javascript trick to keep the session alive - and not refreshing the full page.

<img id="keepAliveIMG" width="1" height="1" src="/img/ui/spacer.gif?" /> 

<script language="javascript" type="text/javascript"> 
    var myImg = document.getElementById("keepAliveIMG");

    if (myImg){
        window.setInterval(function(){
              myImg.src = myImg.src.replace(/\?.*$/, '?' + Math.random());
            }, 6000);
    }   
</script>

(change the time on timer as you like - now is on 6sec)

Similar post: http://stackoverflow.com/questions/3308918/what-is-the-best-approach-to-handle-session-timeouts-in-asp-net/3309046#3309046

这篇关于自动刷新ASP.NET网页定义的时间间隔后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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