本文介绍了以时间间隔显示值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在标签中显示一组值{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[^]
更多推荐
以时间间隔显示值
发布评论