首先将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;
16
function 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
<%@ 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;
16
function 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:
1
using System;
2
3
namespace 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
}
using System;2

3
namespace WebApplication24
{5
/// <summary>6
/// Class1 的摘要说明。7
/// </summary>8
public class Class19
{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
}

浙公网安备 33010602011771号