Automatically refresh an ASP.NET web page after a certain interval?

On one of my websites, it took me 15 minutes to automatically refresh the web page.

To do this, I can write the following line of code

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

But I ran into one problem, which after this 15 minute page duration will be updated as a new page load.

On my page, I used a combo box that has a list of cities, there is a case when I select an item from this list in index 3. After that, I just make the page inactive and after 15 minutes the page is refreshed with a script, I write back to automatically message (mentioned above). But the problem is that because of this page, the new page and the code inside (!PostBack)execute reload , which fill the combo box and reset in index 1.

Please help me solve this problem?

My basic requirement is that whenever a user reaches this page and makes it inactive longer, the session should not expire, and therefore I write the script above so that the session is live.

+3
source share
2 answers

javascript, - .

<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>

( - 6 )

: - asp.net

+2

, ( ViewState) , - , . , Page_Load Tick - .

, ,

if (!IsPostBack)
{
}

ASPX

<asp:Timer id="Timer1" Interval="900000" />

900000 15 .

+1

Source: https://habr.com/ru/post/1760691/


All Articles