AjaxPro.Net的例子

AjaxPro.Net是一個優秀的.net環境下的ajax框架
.net 2.0對應的DLL爲AjaxPro.2.dll,這個網上提供下載的地址很多。

一 環境
Windows 2003
VS 2005
AjaxPro 2

二 例子
1) 新建ASP.NET工程
2) 添加AjaxPro.2.dll
3) 修改WEB.CONFIG
4)新建一個頁面ajaxpro.aspx,代碼:

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

<!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>AjaxPro onLoading</title>
</head>
<body>
    
<form id="form1" runat="server">
        
<div id="loadinfo" style="visibility:hidden;position:absolute;left:0px;top:0px;background-color:Red;color:White;">Loading</div>
   
        
<input id="Button1" type="button" value="Get ServerTime" onclick ="javascript:GetTime();void(0)" />

        
<script type="text/javascript" defer="defer">
        
        
// loading效果
        AjaxPro.onLoading = function(b) 
        
{
            var a 
= document.getElementById("loadinfo");
            a.style.visibility 
= b ? "visible" : "hidden";
        }


        function GetTime() 
        
{
            
// 調用服務端方法
            
//調用方法:類名.方法名 (參數爲指定一個回調函數)
            ajaxpro.GetServerTime(callback);
        }


        function callback(res)  
//回調函數,顯示結果
        {
            alert(res.value);
        }

        
</script>
    
</form>
</body>
</html>

5) 後臺代碼:
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;
using AjaxPro;

public partial class ajaxpro : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    
{
        AjaxPro.Utility.RegisterTypeForAjax(
typeof(ajaxpro)); //註冊ajaxPro,括號中的參數是當前的類名
    }


    [AjaxPro.AjaxMethod] 
//申明是ajaxPro方法
    public string GetServerTime()
    
{
        System.Threading.Thread.Sleep(
2000);
        
return DateTime.Now.ToString();
    }

}


三 測試
http://localhost:1966/WebSite2/ajaxpro.aspx

參考:
http://www.cnblogs.com/chy710/archive/2007/04/18/718715.html
     <httpHandlers>
      
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro"/>
    
</httpHandlers>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章