网站上的倒计时是怎样实现的?例如:从30秒跑到0秒,然后再从头来过,怎样实现啊?现在就是30秒到0秒时可以实现了,从头来过就不好办了。各位帮忙啊....

解决方案 »

  1.   

    while(true)
    {
           ...;
    }
      

  2.   

    在页面上放上ajax控件,然后用timer控件没三十秒做个判断从新归成0然后在页面现实咯!
      

  3.   

    ------------------------------------------------------
    ------------------------------------------------------
    前台页面
    ------------------------------------------------------
    ------------------------------------------------------
    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <asp:UpdateProgress ID="UpdateProgress1" runat="server" 
                AssociatedUpdatePanelID="UpdatePanel1">
                <ProgressTemplate>
                    系统处理中请稍候!
                </ProgressTemplate>
            </asp:UpdateProgress>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:Label ID="Label1" runat="server"></asp:Label>
                    <br />
                    <asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick">
                    </asp:Timer>
                </ContentTemplate>
            </asp:UpdatePanel>
        
        </div>
        </form>
    </body>
    </html>
    -------------------------------------------------------------
    -------------------------------------------------------------
    codefile
    -------------------------------------------------------------
    -------------------------------------------------------------
    using System;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Threading;
    public partial class _Default : System.Web.UI.Page 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        public static int i = 31;
        protected void Timer1_Tick(object sender, EventArgs e)
        {
            i = i - 1;
            Label1.Text = i.ToString();
            if (i == 0) 
            {
                i = 31;
            }        
        }
    }
      

  4.   

    楼上这位大哥 using System.Linq; using System.Xml.Linq;
    这两个命名空间是怎么回事,麻烦你再跟我说说吧 .........
      

  5.   

    这两个命名空间在这个简单的例子没有的,就是LINQ查询语言.
    LINQ包括五个部分:LINQ to Objects、LINQ to DataSets、LINQ to SQL、LINQ to Entities、LINQ to XML。
    LINQ to SQL全称基于关系数据的.NET语言集成查询,用于以对象形式管理关系数据,并提供了丰富的查询功能。其建立于公共语言类型系统中的基于SQL的模式定义的集成之上,当保持关系型模型表达能力和对底层存储的直接查询评测的性能时,这个集成在关系型数据之上提供强类型。
    LINQ to XML在System.Xml.LINQ命名空间下实现对XML的操作。采用高效、易用、内存中的XML工具在宿主编程语言中提供XPath/XQuery功能等
    想深入学习的话建议你看这里
    http://www.cnblogs.com/lyj/archive/2008/01/06/1027646.html
    不知道是否对你有用?
      

  6.   

    我试过了上面的代码怎么不好用,    protected void Timer1_Tick(object sender, EventArgs e) 
        { 
            i = i - 1; 
            Label1.Text = i.ToString(); 
            if (i == 0) 
            { 
                i = 31; 
            }         
        } 
    这个事件怎样才能触发啊 ?
      

  7.   

    这是一个Timer控件,在工具箱中能找到,它有一个Tick事件,然后设置它的 Interval="1000"属性为1秒中触发一次,这样每隔一秒就会触发一次,它上面的代码应该不会有太大的问题
      

  8.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="_Default2" %><%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        Namespace="System.Web.UI" TagPrefix="asp" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head id="Head1" runat="server"> 
        <title>无标题页 </title> 
    </head> 
    <body> 
        <form id="form1" runat="server"> 
        <div> 
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <br />
            <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
                <ProgressTemplate>
                    系统处理中请稍候!
                </ProgressTemplate>
            </asp:UpdateProgress>
            <br />
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:Label ID="Label1" runat="server"></asp:Label><br />
                    <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick">
                    </asp:Timer>
                </ContentTemplate>
            </asp:UpdatePanel>
        
        
        </div> 
        </form> 
    </body> 
    </html> 
    using System;
    using System.Configuration;
    using System.Data;using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;using System.Xml;
    using System.Threading;
    public partial class _Default2 : System.Web.UI.Page
    {   
        public static int i = 31;    protected void Page_Load(object sender, EventArgs e)
        {
            //i = i - 1;
            //Label1.Text = i.ToString();
            //if (i == 0)
            //{
            //    i = 31;
            //}    }
        protected void Timer1_Tick(object sender, EventArgs e)
        {
            i = i - 1;
            Label1.Text = i.ToString();
            if (i == 0)
            {
                i = 31;
            }
        }
    }
    不知哪里有问题Timer1_Tick事件不触发