榕树下。。。

在成功的道路上,你没有耐心去等待成功的到来,那么,你只好用一生的耐心去面对失败
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

AJAX简单例程

Posted on 2006-02-17 16:04  农村的芬芳  阅读(929)  评论(0)    收藏  举报

首先将ajax.dll引入项目

*.ASPX页面:

 1<%@ Page language="c#" Codebehind="WebForm19.aspx.cs" AutoEventWireup="false" Inherits="WebApplication2.WebForm19" %>
 2<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
 3<HTML>
 4    <HEAD>
 5        <title>WebForm19</title>
 6        <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
 7        <meta name="CODE_LANGUAGE" Content="C#">
 8        <meta name="vs_defaultClientScript" content="JavaScript">
 9        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
10    </HEAD>
11    <body MS_POSITIONING="GridLayout">
12        <form id="Form1" method="post" runat="server">
13            <FONT face="宋体"><INPUT style="Z-INDEX: 101; LEFT: 304px; POSITION: absolute; TOP: 96px" type="button" value="Button" onclick="Test1()"></FONT>
14        </form>
15        <script>

        var the_timeout;
16function Test1()
17                        {
18                           
19                            Class1.wjytest(1,"测试",test2);
20                           the_timeout = setTimeout("Test1();", 10000); 
21                        }

22                        function test2( str )
23                        {
24                            alert(str.value);
25                        }

26        </script>
27    </body>
28</HTML>
29


*.aspx.cs
Ajax.Utility.RegisterTypeForAjax(typeof(WebApplication2.Class1));


class1:

 1using System;
 2
 3namespace WebApplication2
 4{
 5    /// <summary>
 6    /// Class1 的摘要说明。
 7    /// </summary>

 8    public class Class1
 9    {
10        public Class1()
11        {
12            //
13            // TODO: 在此处添加构造函数逻辑
14            //
15        }

16        [Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)]
17        public static string wjytest(string id,string name1)
18        {
19            string name = "";
20            if ( id == "1")
21                name = "这是第一个名称"+name1;
22
23            return name;
24
25        }

26
30        }

31    }

32}