How to Page Refresh automatically for every 60 sec...?

Posted by Nandkishorre under ASP.NET on 10/13/2012 | Points: 10 | Views : 24180 | Status : [Member] | Replies : 7
Hi,

I need web page refresh for every 60sec and redirect to another page on without operation on page. If am doing any operation on page not refreshed and not redirected to another page.

For example take 3 webpages.
There is no opeartion on page 1 for 60 sec automatically redirect to page2.
There is no opeartion on page 2 for 60 sec automatically redirect to page3,
If there is doing any operation not redirect to another webpage.

If any one know about this Reply me.

Regards
Nanda Kishore.CH .




Responses

Posted by: Sourabh07 on: 10/14/2012 [Member] Starter | Points: 25

Up
0
Down
For this, you just have to add the timer control in the web form for refreshing the page automatically...

eg:

<asp:Timer ID="tm" Interval="1000" runat="server"></asp:Timer>

In order to refresh the page after 60 seconds, you have to give the Interval=60000 ( 1second=1000 ).

Note: for using the Timer control it is required to add Scriptmanager in the web form before the Timer control eg:

<asp:ScriptManager ID="sm" runat="server"></asp:ScriptManager>
<asp:Timer ID="tm" Interval="1000" runat="server"></asp:Timer>






Sourabh07

Nandkishorre, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Me_Himanshu on: 10/18/2012 [Member] Starter | Points: 25

Up
0
Down
If you dont want to add ajax control then here is an alternative
Here is a solution from code behind.
In page load event ,just add the following line
Response.AddHeader("REFRESH", "60;URL=page you want to reload.aspx");
for e.g
in pageload event
if(!ispostback)
{
Response.AddHeader("REFRESH", "60;URL=yourpage.aspx");
}
60 here means 60 seconds.you can change the time as per your requirement

Though an advantage of using ajax is that ajax makes partial page refresh.
Happy coding

Himanshu Pandey

Nandkishorre, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Me_Himanshu on: 10/18/2012 [Member] Starter | Points: 25

Up
0
Down
Saurabh Mahajan
Another solution other than Ajax control we can have is from code behind.
In page load event ,just add the following line
Response.AddHeader("REFRESH", "60;URL=page you want to reload.aspx");
for e.g
in pageload event
if(!ispostback)
{
Response.AddHeader("REFRESH", "60;URL=yourpage.aspx");
label1.text=system.datetime.now.tostring(); //this label is for noticing the change in time after every 60 seconds to vindicate occurrence the page load
}
60 here means 60 seconds.you can change the time as per your requirement

but ajax is better than this,coz ajax makes the partial page refresh.
Happy coding

Himanshu Pandey

Nandkishorre, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vasanthmvp on: 10/18/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Me_Himanshu,
Though we can do in this way, it is slow compared to AJAX. By using Response.AddHeader() the whole page getting refreshed, each time whole page is made as a request. But, by ajax, only a portion of page under update panel is changed. Hence, ajax is fast when compared. You can see the performance by taking datetime display example.

Regards,

Awesome Coding !! :)

Nandkishorre, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Me_Himanshu on: 10/18/2012 [Member] Starter | Points: 25

Up
0
Down
Thanks for the information.
Regards


Himanshu Pandey

Nandkishorre, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajupatil on: 10/25/2012 [Member] Starter | Points: 25

Up
0
Down
try this..

Response.AppendHeader("Refresh", "60");

In ur page load event...

Nandkishorre, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vivekjj on: 11/1/2012 [Member] Starter | Points: 25

Up
0
Down
hi Rajupatil its workings thanks,and one more need without loading the page but i have to refresh like update panel in every 60 sec is there possible?

Nandkishorre, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response