计时执行后台方法2

前台

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  
<title>Untitled Page</title>
  
<script language="javascript" type="text/javascript">
    
    
//总记录
    var count=3;
    
//记数器
    var i=0;
    
//秒数组
    var ary=[5000,6000,7000];
    
//时钟变量
    var t;
    
    
//调用后台程序方法
    function ServerFunction(msg)
    {
        PageMethods.Msg(msg,End);
    }
    
    
//开始
    function Begin()
    {
        ShowContent(ary[i])
    }
    
//调用更新
    function UpTimes()
    {
        
var sec=$get("hdnTimes").value;
        sec
=sec-1;
    
        $get(
"lblTimes").innerHTML=sec;
        $get(
"hdnTimes").value=sec;
  
        
if(sec==0)
        {    
            i
=i+1;
            
if(i<count)
            {
            
                ShowContent(ary[i]);
            }
            
if(i==count)
            {   
                $get(
"lblTitle").innerHTML="该回家了。下班了";
                $get(
"btnBegin").style.display="none";
                $get(
"tb"+i).style.display="none"
                $get(
"lblTimes").innerHTML="";
                
                clearTimeout(t)
               
                
                Out();
                
return;
            }
            
else
            {
            
                
if(i<count)
                {
                
                     ServerFunction(i);
                }
            }
        }
        
else
        {
          t
=setTimeout("UpTimes()",1000);
        }
    }
    
//确定
    function CheckEnter()
    {
         clearTimeout(t);
         i
=i+1;
         ShowContent(ary[i])
    }
    
//信息显示隐藏
    function ShowContent(seconds)
    {
        
        
if(i>0)
        {
            $get(
"tb"+i).style.display="none"
        }
    
        
var index=i+1;
        $get(
"tb"+index).style.display="inline";
        $get(
"lblTimes").innerHTML=(seconds/1000+1);
        $get("hdnTimes").value=(seconds/1000+1);
        UpTimes();
       
    }
    
//测式对话
    function End(msg)
    {
        alert(msg);
    }
    
function Out()
    {
        End(
"见面完事");
    } 
    
    
</script>
   
</head>
<body onunload="Out()">
    
<form id="form1" runat="server">
        
<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server" />
           
<div>
               
<br /><input id="btnBegin" type="button"
                value
="开始" onclick="Begin();" />
                
           
<asp:Label ID="lblTitle" runat="server" Text="倒计时:"></asp:Label> <asp:Label ID="lblTimes" runat="server" Text="Label"></asp:Label>
           
<input id="hdnTimes" type="hidden" />
                
<br />
            
<table id="tb1" runat="server"  style=" display:none;" width="400px" border="1" cellpadding="2" cellspacing="3" >
            
<tr><td>
                初次见面!
<input id="Button2" type="button" onclick="CheckEnter()" value="next" /><input id="Button5" type="button" onclick="CheckEnter()" value="确定" /></td></tr>
            
</table>    
            
<table id="tb2" runat="server" width="400px" style=" display:none;" border="1" cellpadding="2" cellspacing="3" >
            
<tr><td>
                你好!
<input id="Button3" type="button" onclick="CheckEnter()" value="next" /><input id="Button6" type="button" onclick="CheckEnter()" value="确定" /></td></tr>
            
</table>
             
<table id="tb3" runat="server" width="400px" style=" display:none;" border="1" cellpadding="2" cellspacing="3" >
            
<tr><td>
                再见!
<input id="Button4" type="button" onclick="CheckEnter()" value="next" /><input id="Button7 onclick="CheckEnter()" type="button" value="确定" /></td></tr>
            
</table>
        
</div>
    
</form>
</body>
</html>

后台

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Services;
public partial class _Default : System.Web.UI.Page 
{
    
protected void Page_Load(object sender, EventArgs e)
    {
       
    }
    [WebMethod]
    
static public string Msg(string msg)
    {
        
return msg;
    }
}

 

posted @ 2008-10-08 17:00  天纯蓝  阅读(232)  评论(0编辑  收藏  举报