每10秒刷新一次页面 [英] Refreshing page every 10 seconds

查看:92
本文介绍了每10秒刷新一次页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有以下DataList的代码,而在c#中的代码却可以正常工作.

我试图弄清楚如何每10秒刷新一次页面,我想放置一个计时器,但不确定应该将它放在哪个位置.

有什么想法怎么做?谢谢

Hi,

I have following code for DataList and the code behind in c# it is working fine.

I am trying to figure out how to refresh the page it every 10 seconds, i was thinking of placing timer but not sure which place it should go.

Any ideas how to do it? Thanks

<asp:DataList ID="DataList1" runat="server" RepeatColumns="3" CellSpacing="3"
    RepeatDirection="Horizontal"  HorizontalAlign="Left"
    DataKeyField="email" DataSourceID="SqlDataSource1" Width="900px"
    onselectedindexchanged="DataList1_SelectedIndexChanged">
    <itemtemplate>

              Skipping the code here which is working fine
                </itemtemplate>


在c#中


And in c#

protected void Page_Load(object sender, EventArgs e)
{
  email.Text = "" + Session["email"];
}

protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{

        if (!this.IsPostBack)
        {
            con.Close();
            con.Open();
            cmd = new SqlCommand("SELECT C, P FROM dr WHERE email='" + email.Text + "'", con);
           
            dr = cmd.ExecuteReader();
        
        }
}

推荐答案

为什么HTML可以为您提供复杂的解决方案?

在页面上使用HTML元刷新标记

Why go for any complex solution when the HTML can do it for you?

Use the HTML meta refresh tag on your page

<meta http-equiv="refresh" content="600"> 



http://webdesign.about.com/od/metataglibraries/a/aa080300a.htm



http://webdesign.about.com/od/metataglibraries/a/aa080300a.htm


尝试一下...

Try this...

<meta http-equiv="refresh" content="600">


一个页面被加载,它在客户端上,因此您需要进行刷新.您可以通过以下两种方式进行此操作.

1)页面指令
http://www.codelifter.com/main/tips/tip_011.shtml [ ^ ]

2)使用setTimeout函数

http://forums.digitalpoint.com/showthread.php?t=922267 [ ^ ]

我认为两者都有点烦人,我不喜欢整页刷新.

您还可以查看anajax调用以部分更新页面,仅刷新页面中显示数据的部分.
One the page is loaded, it''s on the client so that''s where you need to make the refresh happen. There''s a couple of ways you can do this.

1) Page directive
http://www.codelifter.com/main/tips/tip_011.shtml[^]

2) Using the setTimeout function

http://forums.digitalpoint.com/showthread.php?t=922267[^]

Both are a bit annoying in my opinion, I don''t like whole page refreshes.

You could also look into anajax call to partially update the page, refreshing only the part of the page that''s displaying the data.


这篇关于每10秒刷新一次页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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