以时间间隔显示值

编程入门 行业动态 更新时间:2024-10-27 16:38:28
本文介绍了以时间间隔显示值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在标签中显示一组值{20,21,22,23,24,25,26,27,28,29,30}。 我使用了计时器及其工作正常, 但问题是页面重新加载。 没有重新加载页面如何使它成为可能。 我的代码是: .aspx页面:

I want to display set of values{20,21,22,23,24,25,26,27,28,29,30} in a label. I used timer and its working fine, But the issue is the page getting reloaded. without reloading the page how to make it possible. My Code is: .aspx page:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="www.w3/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <div style="height: 100px; width: 100px; background-color: LightSkyBlue; border-radius: 3px;"> <asp:Label ID="Label1" runat="server" Text=""></asp:Label> </div> </div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:Timer ID="Timer1" runat="server" Interval="2000" OnTick="Timer1_Tick"> </asp:Timer> </form> </body> </html>

代码背后:

Code behind:

public void user_online() { Timer1.Interval = 2000; } protected void Timer1_Tick(object sender, EventArgs e) { string conn = ConfigurationManager.ConnectionStrings["connection_name"].ToString(); SqlConnection con = new SqlConnection(conn); if (con.State == ConnectionState.Closed) { con.Open(); } string q = "select top 1 * from temp_no order by newid()"; SqlCommand cmd = new SqlCommand(q, con); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); Label1.Text = dr["student_online"].ToString(); if (con.State == ConnectionState.Open) { con.Close(); con.Dispose(); } }

推荐答案

尝试使用 UpdatePanel [ ^ ]。 UpdatePanel控件概述 [ ^ ] Try using an UpdatePanel[^]. UpdatePanel Control Overview[^]

更多推荐

以时间间隔显示值

本文发布于:2023-10-16 11:24:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1497418.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:间隔   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!