您的位置:首页 > 产品设计 > UI/UE

Ajax.Net Professional——A quick guide how to start(AjaxPro开始向导)

2012-05-27 17:52 531 查看
Because I could not write a documentation I will show you here how to start:

Download the latest Ajax.NET Professional files from
www.schwarz-interactive.de
Add a reference to the AjaxPro.2.dll (for the .NET 1.1 Framework use AjaxPro.dll)
Add following lines to your web.config:

因为我不会写文档,我将以如下方式告诉你如何开始:

(1)下载最新版的AjaxPro文件

(2)添加AjaxPro的引用。(.NET1.1使用AjaxPro.dll,其他版本的.NET使用AjaxPro.2.dll)

在web.config文件中添加以下几行:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<httpHandlers>
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro.2"/>
</httpHandlers>

[...]

</system.web>
</configuration>

ashx百度百科:http://baike.baidu.com/view/3799515.htm
PS:CSDN的编辑器有点问题,源代码里边并没有<strong>编辑,该标记是CSDN的代码格式化编辑,在编辑页面中没有该标记,但在发布后的页面中却多了该标记,要注意把它删掉。

Now, you have to mark your .NET methods with an AjaxMethod attribute:

然后,你需要使用AjaxMethod属性来标注你的.NET方法。

[AjaxPro.AjaxMethod]
public DateTime GetServerTime()
{
return DateTime.Now;
}

To use the .NET method on the client-side JavaScript you have to register the methods, this will be done to register a complete class to Ajax.NET:

在客户端使用JS来调用.NET方法,你需要注册这些方法(被JS调用的.NET方法)。通过注册一个完整的类名来实现。

namespace MyDemo
{
public class _Default
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(_Default));
}

[AjaxPro.AjaxMethod] public DateTime GetServerTime() { return DateTime.Now; }
}
}

ps:使用AjaxPro.Utility.RegisterTypeForAjax()方法来注册一个类为Ajax类。参数为类名,可通过使用typeof操作符获取。

If you start the web page two JavaScript includes are rendered to the HTML source.
如果你的web页面包含以下两段JS代码,在HTML源代码中将会显示为下边代码所示:

To call a .NET method form the client-side JavaScript code you can use following syntax:
在客户端通过JS代码来调用一个.NET(服务器端)方法,使用下边所示的语法:

function getServerTime()
{
MyDemo._Default.GetServerTime(getServerTime_callback);  // asynchronous call
}

// This method will be called after the method has been executed
// and the result has been sent to the client.

function getServerTime_callback(res)
{
alert(res.value);
}

PS:使用完全的限定名,命名空间.类名.方法名:MyDemo._Default.GetServerTime在客户端,使用JS代码,方法getServerTime调用服务器端的GetServerTime方法来获取时间,返回值可以直接赋值给客户端JS的一个变量或者通过回调函数,将返回值发送给回调函数,作为其参数,然后在回调函数中做处理。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: