AJAX原来没想象中难用,简单一用!
原来一直以为AJAX用起来可能很麻烦,昨天下了一个AjaxPro,顺便找了一下资料,今天一用很快就能上手!以下说说我用的,在项目中我我直接用WebForm1.aspx来做测试页面!
首先将AjaxPro.DLL在项目中引用!
可以通过在http://ajax.schwarz-interactive.de/csharpsample/default.aspx下载Ajax.NET Professional 。
在web.config配置一下:

<system.web>
<httpHandlers>
<add verb="*" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro" />
</httpHandlers>



</system.web>
页面:WebForm1.aspx
在这个项目中[AjaxPro.AjaxClass("Web")]和[AjaxPro.AjaxMethod]也是必要的,如果没有在Javascript调用时会出错!
其实代码很少,文字介绍也很少,写这些只是想让想学AJAX方便快速的会用!想要等深入研究话,可以在找些资料学一下,也可以看一下下面我参考的资料!
参考资料:http://news.csdn.net/news/newstopic/28/28204.shtml!
首先将AjaxPro.DLL在项目中引用!
可以通过在http://ajax.schwarz-interactive.de/csharpsample/default.aspx下载Ajax.NET Professional 。
在web.config配置一下:

<system.web>
<httpHandlers>
<add verb="*" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro" />
</httpHandlers>


</system.web>页面:WebForm1.aspx
1 using System;
2 using System.Collections;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Web;
7 using System.Web.SessionState;
8 using System.Web.UI;
9 using System.Web.UI.WebControls;
10 using System.Web.UI.HtmlControls;
11
12
13 namespace Fly
14 {
15 /**//// <summary>
16 /// WebForm1 的摘要说明。
17 /// </summary>
18 [AjaxPro.AjaxClass("Web")]
19 public class WebForm1 : System.Web.UI.Page
20 {
21 private void Page_Load(object sender, System.EventArgs e)
22 {
23 // 在此处放置用户代码以初始化页面
24 AjaxPro.Utility.RegisterTypeForAjax(typeof(WebForm1));
25 }
26
27
28 [AjaxPro.AjaxMethod]
29 public string ceshi()
30 {
31 return "测试?";
32 }
在Page_Load先登记一下要用的类名AjaxPro.Utility.RegisterTypeForAjax(typeof(WebForm1));2 using System.Collections;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Web;
7 using System.Web.SessionState;
8 using System.Web.UI;
9 using System.Web.UI.WebControls;
10 using System.Web.UI.HtmlControls;
11
12
13 namespace Fly
14 {
15 /**//// <summary>
16 /// WebForm1 的摘要说明。
17 /// </summary>
18 [AjaxPro.AjaxClass("Web")]
19 public class WebForm1 : System.Web.UI.Page
20 {
21 private void Page_Load(object sender, System.EventArgs e)
22 {
23 // 在此处放置用户代码以初始化页面
24 AjaxPro.Utility.RegisterTypeForAjax(typeof(WebForm1));
25 }
26
27
28 [AjaxPro.AjaxMethod]
29 public string ceshi()
30 {
31 return "测试?";
32 }
在这个项目中[AjaxPro.AjaxClass("Web")]和[AjaxPro.AjaxMethod]也是必要的,如果没有在Javascript调用时会出错!
1
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="Fly.WebForm1" %>
2
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
3
<HTML>
4
<HEAD>
5
<title>WebForm1</title>
6
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
7
<meta content="C#" name="CODE_LANGUAGE">
8
<meta content="JavaScript" name="vs_defaultClientScript">
9
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
10
<script language="javascript">
11
function csValue()
12
{
13
var fd = Web.ceshi();
14
alert(fd.value);
15
}
16
</script>
17
</HEAD>
18
<body MS_POSITIONING="GridLayout">
19
<form id="Form1" method="post" runat="server">
20
<INPUT onclick="csValue()" type="button" value="Button">
21
</form>
22
</body>
23
</HTML>
这样就可以成功调用了!简单吧!
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="Fly.WebForm1" %>2
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >3
<HTML>4
<HEAD>5
<title>WebForm1</title>6
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">7
<meta content="C#" name="CODE_LANGUAGE">8
<meta content="JavaScript" name="vs_defaultClientScript">9
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">10
<script language="javascript">11
function csValue()12
{13
var fd = Web.ceshi();14
alert(fd.value); 15
}16
</script>17
</HEAD>18
<body MS_POSITIONING="GridLayout">19
<form id="Form1" method="post" runat="server">20
<INPUT onclick="csValue()" type="button" value="Button">21
</form>22
</body>23
</HTML>其实代码很少,文字介绍也很少,写这些只是想让想学AJAX方便快速的会用!想要等深入研究话,可以在找些资料学一下,也可以看一下下面我参考的资料!
参考资料:http://news.csdn.net/news/newstopic/28/28204.shtml!
posted on 2005-11-01 16:28 Juny Beendy 阅读(1011) 评论(0) 收藏 举报

浙公网安备 33010602011771号