如何使用Javascript刷新asp.net中页面的内容 [英] how to refreshing the content of the page in asp.net By using Javascript

查看:57
本文介绍了如何使用Javascript刷新asp.net中页面的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

haiiiiiiiiiiiiiiiiiii



在我的申请中,我使用的是饼图。我想在加载页面时每2分钟自动刷新一次图表。为此,我正在使用计时器控件。我想在页面加载时刷新页面内容(图表),但不是任何事件来启动计时器。但是这里当任何事件被触发然后计时器启动但我想要在页面加载时启动计时器请帮助我





这是Javascript函数



< script type =text / javascript>

window.onload = function(){

window.displayImgCount = 0;

函数cycleImage(){

GetData();

setTimeout(cycleImage,5000) ;

}

cycleImage();

}



函数GetData( ){

调试器;



PageMethods.GetValidCharts();

}



这是我的页面设计中的计时器标签



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

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





计时器点击事件是





Timer click event is

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

推荐答案

你好MANI,



请写你的代码

Hi MANI,

Please write your code inside
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. 
            }
        }


请尝试以下代码:



Try following code:

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();
}





从aspx页面删除控件:



Remove the control from aspx page :

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


这篇关于如何使用Javascript刷新asp.net中页面的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆