Auto refresh the page and keep the viewstate of the page on each refresh

Posted: August 21, 2009 in ASP.NET, Javascript
Tags: , , , ,

Today I am writing about how you can auto-refresh the page and still how you can manage the view-state of the page.

There may be requirement to fill up a long lasting form and this might take you a longer time to think or type. Now the general problem that occurs while filling up this kind of form is when you submit the form the session got expired or the timeout event occurs. So to overcome this situation we can set some timer to that particular page for refresh so that after several minutes it got refreshed automatically and we did not face any timeout or session related issues.

Now there are several ways to auto-refresh the page, the one is to put meta tag like <meta http-equiv="refresh" content="600">. What this tag will do is it will refresh the page after every 10 minutes, but when the page gets refresh then it will not persist the view-state of the page. This means if you are filling up any form and the page gets refreshed then you will not able to get all the filled content and the page will get loaded in its original form.

There was one requirement where I need to auto refresh the page as well as need to keep the view-state of the page. To achieve this I have put a simple JavaScript code on BODY tag of my page as below:

<Body onload="setTimeout('Form1.submit();', 600000);">
<form id="Form1" method="post" runat="server">

Here this JavaScript method “setTimeout()” will submit your form data after every 10 minutes and the page will also get refreshed so that it will also persist the view-state of the page after auto refresh of the page. Please note that the time 600000 here is in milliseconds. (1 second = 1000 milliseconds)

Happy Programming!

Advertisements
Comments
  1. My friend, THANKS A LOT!!! I ran into this problem and your solution worked like a charm!!

    Just wanted to let you know that.

    Regards

    Victor Espina
    Venezuela

  2. Tan says:

    Didn’t work. IT SUCKS!Q!!

  3. it’s awesome. I just set the timer for 10 min.

    Simple rules,
    for 10 min; 10 * 60 * 1 000 = 600 000
    for 15 min; 15*60*1000 = 900 000

    thanks for the great share.

  4. Hei, how to create this auto refresh page in wordpress page?

    Thanks

  5. you are actually a just right webmaster. The web site loading velocity is incredible. It sort of feels that you are doing any distinctive trick. Furthermore, The contents are masterpiece. you have performed a wonderful job on this topic!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s