2天时间的查资料学习,终于走完了AJAX学习的第一步,第一个例子成功完成……

源代码:

ASPX:

 1<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
 2
 3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 4
 5<html xmlns="http://www.w3.org/1999/xhtml" >
 6<head runat="server">
 7    <title>李智的第一个AJAX应用程序</title>
 8    <script language="javascript" type="text/javascript">
 9        function ClientAdd()
10        {
11            var first = document.all("first");
12            var second = document.all("second");
13            var result = document.all("result");
14            result.value = _Default.ServerSideAdd(first.value,second.value).value;
15        }

16    
</script>
17</head>
18<body>
19    <form id="form1" runat="server">
20    <div>
21    <input id="first" type="text" size="5" /> + <input id="second" type="text" size="5" /> = <input id="result" type="text" size="5" />&nbsp;<input id="calc" type="button" value="计算" onclick="ClientAdd()" />
22    </div>
23    </form>
24</body>
25</html>
26

CS:
 1using System;
 2using System.Data;
 3using System.Configuration;
 4using System.Web;
 5using System.Web.Security;
 6using System.Web.UI;
 7using System.Web.UI.WebControls;
 8using System.Web.UI.WebControls.WebParts;
 9using System.Web.UI.HtmlControls;
10using AjaxPro;
11
12
13[System.Web.Services.WebService]
14public partial class _Default : System.Web.UI.Page
15{
16    
17    protected void Page_Load(object sender, EventArgs e)
18    {
19        AjaxPro.Utility.RegisterTypeForAjax(typeof(_Default));
20    }

21    [AjaxPro.AjaxMethod]
22    public static int ServerSideAdd(int firstNumber, int secondNumber)
23    {
24        return firstNumber + secondNumber;
25    }

26}

27


Web.Config
 1<?xml version="1.0"?>
 2<!-- 
 3    注意: 除了手动编辑此文件以外,您还可以使用 
 4    Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的
 5     “网站”->“Asp.Net 配置”选项。
 6    设置和注释的完整列表在 
 7    machine.config.comments 中,该文件通常位于 
 8    \Windows\Microsoft.Net\Framework\v2.x\Config 中
 9-->
10<configuration>
11    <appSettings/>
12    <connectionStrings/>
13    <system.web>
14    <httpHandlers>
15      <!-- Register the ajax handler 手动添加注册----LiZhi-->
16      <add verb="*" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro"/>
17    </httpHandlers>
18    <!-- 
19            设置 compilation debug="true" 将调试符号插入
20            已编译的页面中。但由于这会 
21            影响性能,因此只在开发过程中将此值 
22            设置为 true。
23        -->
24        <compilation debug="false">
25            <assemblies>
26                <add assembly="System.Drawing.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/></assemblies></compilation>
27        <!--
28            通过 <authentication> 节可以配置 ASP.NET 使用的 
29            安全身份验证模式,
30            以标识传入的用户。 
31        -->
32        <authentication mode="Windows"/>
33        <!--
34            如果在执行请求的过程中出现未处理的错误,
35            则通过 <customErrors> 节可以配置相应的处理步骤。具体说来,
36            开发人员通过该节可以配置
37            要显示的 html 错误页
38            以代替错误堆栈跟踪。
39
40        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
41            <error statusCode="403" redirect="NoAccess.htm" />
42            <error statusCode="404" redirect="FileNotFound.htm" />
43        </customErrors>
44        -->
45    </system.web>
46</configuration>
47
posted on 2007-01-13 11:19  Achilles.NET  阅读(462)  评论(2编辑  收藏  举报