前台代码!
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>倒计时</title></head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div >
        距离
        <asp:TextBox ID="TextBox1" runat="server" Text="2011-03-25 16:20:59"></asp:TextBox>
        <br /><asp:Button ID="Button1" runat="server" Text="确认" Enabled="true" 
            Height="33px" Width="123px"/><br />还有
        <asp:UpdatePanel ID="UpdatePanelCountdown" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:Label ID="lblTimerDays" runat="server" Text="0" ForeColor="Red" />天
                <asp:Label ID="lblTimerHours" runat="server" Text="0" ForeColor="Red" />时
                <asp:Label ID="lblTimerMinutes" runat="server" Text="0" ForeColor="Red" />分
                <asp:Label ID="lblTimerSeconds" runat="server" Text="0" ForeColor="Red" />秒
                <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick1" />
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
  
    </form>
</body>
</html>后台代码!
protected void Page_Load(object sender, EventArgs e)
    {
        string time = this.TextBox1.Text;
        DateTime EndTime = Convert.ToDateTime(time);//结束时间
        TimeSpan CountdownSpan;//时间间隔        if (!IsPostBack)
        {
            DateTime NowTime = DateTime.Now;
            CountdownSpan = EndTime - NowTime;
            if (CountdownSpan.TotalSeconds > 0)
            {
                lblTimerDays.Text = CountdownSpan.Days.ToString();
                lblTimerHours.Text = CountdownSpan.Hours > 10 ? CountdownSpan.Hours.ToString() : "0" + CountdownSpan.Hours.ToString();
                lblTimerMinutes.Text = CountdownSpan.Minutes > 10 ? CountdownSpan.Minutes.ToString() : "0" + CountdownSpan.Minutes.ToString();
                lblTimerSeconds.Text = CountdownSpan.Seconds > 10 ? CountdownSpan.Seconds.ToString() : "0" + CountdownSpan.Seconds.ToString();
            }
        }    }
    protected void Timer1_Tick1(object sender, EventArgs e)
    {
        string time = this.TextBox1.Text;
        DateTime EndTime = Convert.ToDateTime(time);//结束时间
        TimeSpan CountdownSpan;//时间间隔        DateTime NowTime = DateTime.Now;
       
        CountdownSpan = EndTime - NowTime;
        if (CountdownSpan.TotalSeconds > 0)
        {
            lblTimerDays.Text = CountdownSpan.Days.ToString();
            lblTimerHours.Text = CountdownSpan.Hours > 10 ? CountdownSpan.Hours.ToString() : "0" + CountdownSpan.Hours.ToString();
            lblTimerMinutes.Text = CountdownSpan.Minutes > 10 ? CountdownSpan.Minutes.ToString() : "0" + CountdownSpan.Minutes.ToString();
            lblTimerSeconds.Text = CountdownSpan.Seconds > 10 ? CountdownSpan.Seconds.ToString() : "0" + CountdownSpan.Seconds.ToString();
        }
        //我在这里判断的,怎么不行???
        //else
        //{
        //    //我就写这么一小句,时间到的时候,button的enable变成灰色
        //    this.Button1.Enabled = false;
        //}
        
    }时间到了,就把按钮变成灰色!我else这样写不对!在load中加也不行!怎样才行??

解决方案 »

  1.   

    用js脚本的setInterval()来做吧。Timer控件是运行在服务器端的,根本没办法控制下载到客户端的东西
      

  2.   

    前台改成<html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>倒计时</title></head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <div >
            距离
            <asp:TextBox ID="TextBox1" runat="server" Text="2011-03-25 17:04:40"></asp:TextBox>
           
            <asp:UpdatePanel ID="UpdatePanelCountdown" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                <asp:Button ID="Button1" runat="server" Text="确认" Enabled="true" 
                Height="33px" Width="123px"/>还有 <br /><br />
                    <asp:Label ID="lblTimerDays" runat="server" Text="0" ForeColor="Red" />天
                    <asp:Label ID="lblTimerHours" runat="server" Text="0" ForeColor="Red" />时
                    <asp:Label ID="lblTimerMinutes" runat="server" Text="0" ForeColor="Red" />分
                    <asp:Label ID="lblTimerSeconds" runat="server" Text="0" ForeColor="Red" />秒
                    <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick1" />
                </ContentTemplate>
            </asp:UpdatePanel>
        </div>
      
        </form>
    </body>
    </html>
    需要将确定按钮放入UpdatePanel
      

  3.   

    谁能给我个js或者jquery倒计时的代码
    第一:时间是自己设定的第二:时间到了,按钮失效!像这样的!在网上找了许多,不知道怎么设置时间到了,就让按钮失效,谢谢!
      

  4.   

    就用js来控制,那个你可以看人家写的js代码,然后进行修改
      

  5.   

    http://www.google.com.hk/search?sourceid=chrome&ie=UTF-8&q=js+%E5%80%92%E8%AE%A1%E6%97%B6