Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i'm having a scenario to call load event after every 5 seconds or 10 seconds some one help me.
Posted

There are various ways to refresh page automatically after certain interval of time.

Method #1:
Using META tag in head section: Meta Refresh Tag[^]
Sample:
HTML
<meta http-equiv="Refresh" content="10;URL=http://www.yourURL.com"></meta>


You can append meta tag from code behind too:
C#
Response.AppendHeader("Refresh", "10; URL=http://www.yourURL.com")


Method #2:
Using Timer Control[^]: It allow you to do postbacks at certain intervals: Timer control[^]:
Sample;
XML
<asp:Timer runat="server" id="UpdateTimer" interval="5000" ontick="UpdateTimer_Tick" />
<asp:UpdatePanel runat="server" id="TimedPanel" updatemode="Conditional">
   <Triggers>
        <asp:AsyncPostBackTrigger controlid="UpdateTimer" eventname="Tick" />
   </Triggers>
   <ContentTemplate>
        <asp:Label runat="server" id="DateStampLabel" />
   </ContentTemplate>
</asp:UpdatePanel>


Method #3:
Using setTimeout in Javascript: Automatically refresh page after some interval[^]
Sample:
XML
function RefreshPage(Period)
{
    setTimeout("location.reload(true);", Period);
}
<body  önload="javaScript:RefreshPage(1000);">


Method #4:
Using Response.AppendHeader method: MSDN: HttpResponse.AppendHeader Method[^]
Sample:
C#
// Page refresh is set to 5 seconds after the client session timeout setting specified in the web.config file.
this.Response.AppendHeader("Refresh",Convert.ToString(Session.Timeout * 60 + 5));


Pick one that suits you.
 
Share this answer
 
v2
you can use timer class and set tick property to 5000
 
Share this answer
 
Comments
deepgalley 20-Jul-12 12:11pm    
No i wan't it in jquery or in ajax.
deepgalley 20-Jul-12 12:11pm    
it should be asynchronous operation

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900