Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
haiiiiiiiiiiiiiiiiiii

In my application i am using pie charts. I want to refresh the charts every 2 min automatically when page is loaded. for this i am using the timer control.I want to refreshing the page content(charts) when page is loaded, but not any event to fire start timer. But here when any event is fired then timer starting but i want start timer at the time of page load please help me


This is the Javascript function

<script type="text/javascript">
window.onload = function(){
window.displayImgCount = 0;
function cycleImage(){
GetData();
setTimeout(cycleImage, 5000);
}
cycleImage();
}

function GetData() {
debugger;

PageMethods.GetValidCharts();
}

This is the timer tag in my page design

XML
<asp:Timer ID="TimerCharts" runat="server" Interval="300000" OnTick="TimerCharts_Tick"  >
          </asp:Timer>


Timer click event is

C#
protected void TimerCharts_Tick(object sender, EventArgs e)
   {
       GetValidCharts();
   }
Posted
Updated 2-Jan-14 18:35pm
v2
Comments
Gitanjali Singh 3-Jan-14 0:50am    
Have u tried window.location.reload();
MANI 14 3-Jan-14 1:19am    
no. where it is used
Gitanjali Singh 3-Jan-14 2:35am    
Add it after Getdata () function and try

Hi MANI,

Please write your code inside
C#
protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            { 
            //Write the timere code here. 
            //This code block will be executed when the page will be loaded first time. 
            }
        }
 
Share this answer
 
Try following code:

C#
protected void Page_Load(object sender, EventArgs e)
{

    if (!IsPostBack)
    {
    //Write the timere code here.
    //This code block will be executed when the page will be loaded first time.
        System.Timers.Timer aTimer = new System.Timers.Timer();
        aTimer.Elapsed += new ElapsedEventHandler(TimerCharts_Tick);
        // Set the Interval to 5 seconds.
        aTimer.Interval = 10000;
        aTimer.Enabled = true;
    }
}

protected void TimerCharts_Tick(object sender, EventArgs e)
{
    GetValidCharts();
}


Remove the control from aspx page :
ASP.NET
<asp:Timer ID="TimerCharts" runat="server" Interval="300000" OnTick="TimerCharts_Tick"  >
          </asp:Timer>
 
Share this answer
 
v2
Comments
Sibasisjena 3-Jan-14 1:33am    
If the above will not work then go through following links, you may get some idea.
Link1

Link2
MANI 14 4-Jan-14 1:59am    
Its working if it is single page. But in my app Having master page thats why its not working automatically. if any click event fire then its statring. please help me how to refreshing page content when page is gets loaded by using timer

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