1、HTML代码:
<%@ Page language="c#" Codebehind="Default.aspx.cs" AutoEventWireup="false" Inherits="AjaxTest._Default" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Default</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript" type="text/javascript">
function getServerTime()
{
document.getElementById( 'Label1' ).innerText = AjaxTest._Default.GetTime().value ;
}
function add( a,b )
{
var a1 = parseInt( a );
var b1 = parseInt( b );
document.getElementById( 'Label2' ).innerText = AjaxTest._Default.AddTwo( a1,b1 ).value;
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table cellpadding="0" cellspacing="0">
<tr>
<td align="center" height="100" valign="bottom"><FONT color="red" size="6">计算两数之和</FONT></td>
</tr>
<tr>
<td>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox id="TextBox2" runat="server"></asp:TextBox>
<input id="Button" type="button" value="计算两数之和" onclick="add( document.getElementById( 'TextBox1' ).value,document.getElementById( 'TextBox2' ).value )">
</td>
</tr>
<tr>
<td><asp:Label id="Label2" runat="server" Width="416px" Height="48px"></asp:Label></td>
</tr>
<tr>
<td align="center" valign="bottom" height="100"><FONT color="red" size="6">获取服务器时间</FONT></td>
</tr>
<tr>
<td><input id="Button1" type="button" value="获得服务器时间" onclick="getServerTime();">
<asp:Label id="Label1" runat="server" Width="264px"></asp:Label></td>
</tr>
</table>
</form>
</body>
</HTML>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Default</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript" type="text/javascript">
function getServerTime()
{
document.getElementById( 'Label1' ).innerText = AjaxTest._Default.GetTime().value ;
}
function add( a,b )
{
var a1 = parseInt( a );
var b1 = parseInt( b );
document.getElementById( 'Label2' ).innerText = AjaxTest._Default.AddTwo( a1,b1 ).value;
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table cellpadding="0" cellspacing="0">
<tr>
<td align="center" height="100" valign="bottom"><FONT color="red" size="6">计算两数之和</FONT></td>
</tr>
<tr>
<td>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox id="TextBox2" runat="server"></asp:TextBox>
<input id="Button" type="button" value="计算两数之和" onclick="add( document.getElementById( 'TextBox1' ).value,document.getElementById( 'TextBox2' ).value )">
</td>
</tr>
<tr>
<td><asp:Label id="Label2" runat="server" Width="416px" Height="48px"></asp:Label></td>
</tr>
<tr>
<td align="center" valign="bottom" height="100"><FONT color="red" size="6">获取服务器时间</FONT></td>
</tr>
<tr>
<td><input id="Button1" type="button" value="获得服务器时间" onclick="getServerTime();">
<asp:Label id="Label1" runat="server" Width="264px"></asp:Label></td>
</tr>
</table>
</form>
</body>
</HTML>
2、CS代码:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace AjaxTest
{
/// <summary>
/// _Default 的摘要说明。
/// </summary>
public class _Default : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox TextBox2;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
AjaxPro.Utility.RegisterTypeForAjax( typeof( _Default ) );
}
Web 窗体设计器生成的代码
[AjaxPro.AjaxMethod]
public int AddTwo( int a,int b )
{
return a + b;
}
[AjaxPro.AjaxMethod]
public DateTime GetTime()
{
return DateTime.Now;
}
}//end class
}
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace AjaxTest
{
/// <summary>
/// _Default 的摘要说明。
/// </summary>
public class _Default : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox TextBox2;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
AjaxPro.Utility.RegisterTypeForAjax( typeof( _Default ) );
}
Web 窗体设计器生成的代码
[AjaxPro.AjaxMethod]
public int AddTwo( int a,int b )
{
return a + b;
}
[AjaxPro.AjaxMethod]
public DateTime GetTime()
{
return DateTime.Now;
}
}//end class
}
3、WEBCONFIG
<httpHandlers>
<add verb="*" path="*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro" />
</httpHandlers>
<add verb="*" path="*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro" />
</httpHandlers>