AjaxPro加载效果的实现

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AjaxGetTime.aspx.cs" Inherits="AjaxGetTime" %>
<!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>
     <script type="text/javascript" defer="defer">
        
        // loading效果
        AjaxPro.onLoading = function(b)
        {
            var a = document.getElementById("loadinfo");
            alert(b);//当加载的时候,b是true,加载完成是false;
            a.style.visibility = b ? "visible" : "hidden";
        }
        function GetTime()
        {
            // 调用服务端方法
            //调用方法:类名.方法名 (参数为指定一个回调函数)
            AjaxGetTime.GetServerTime(callback);
        }
        function callback(res)  //回调函数,显示结果res就是GetServerTime返回的对象,使用value得到它的值
        {
            alert(res.value);
        }
        </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <div id="loadinfo" style="visibility:hidden;position:absolute;left:0px;top:0px;background-color:Red;color:White;">Loading</div>
  
        <input id="Button2" type="button" value="Get ServerTime" onclick ="javascript:GetTime()" />
    </div>
    </form>
</body>
</html>


using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
public partial class AjaxGetTime : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        AjaxPro.Utility.RegisterTypeForAjax(typeof(AjaxGetTime));
    }
    [AjaxPro.AjaxMethod] //申明是ajaxPro方法
    public string GetServerTime()
    {
        System.Threading.Thread.Sleep(2000);
        return DateTime.Now.ToString();
    }
}
posted @ 2008-05-18 22:11  熊忠荣  阅读(459)  评论(0编辑  收藏  举报