Ajax Js倒计时执行后台方法

HTML代码

 

 1<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
 2
 3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 4<html xmlns="http://www.w3.org/1999/xhtml">
 5<head runat="server">
 6    <title>Untitled Page</title>
 7    <script language="javascript" type="text/javascript">
 8    function hello()
 9    {
10        BeginMessage();
11        var t=setTimeout("endMessage('计时结束 5 seconds!')",5000)
12    }

13    function endMessage(msg)
14    {
15        PageMethods.Msg(msg,updateMessages);
16    }

17    function BeginMessage()
18    {
19        PageMethods.Msg("计时开始",updateMessages);
20    }

21    function updateMessages(result)
22    {
23        $get("lbl").innerHTML =result;
24    }

25    
</script>
26</head>
27<body>
28    <form id="form1" runat="server">
29        <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server" />
30        <div>
31            <asp:Label ID="lbl" runat="server" Text="Label"></asp:Label
32            ><input id="Button1" type="button"
33                value="开始" onclick="hello()" />
34        </div>
35    </form>
36</body>
37</html>
38

 

 后台代码

 

Default.aspx.cs
posted @ 2008-09-19 10:48  天纯蓝  阅读(613)  评论(0编辑  收藏  举报