</div> </form> </body> </html>后台: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Default2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //_Default是这里的大类名,网页是Default.aspx在 //它的cs文件里的类是_Default
<%@ Import namespace="value" %>
前台:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script type="text/javascript">
function show2() { //_Default.gets()这是后台的方法 var mes = Default2.gets(); alert(mes.value); }
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" value="click" onclick="show2();" />
</div>
</form>
</body>
</html>后台:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ //_Default是这里的大类名,网页是Default.aspx在 //它的cs文件里的类是_Default
Ajax.Utility.RegisterTypeForAjax(typeof(Default2)); } [Ajax.AjaxMethod] public string gets()
{ return "hello"; }
}
Web.config:
<?xml version="1.0"?>
<!--
有关如何配置 ASP.NET 应用程序的详细信息,请访问
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<httpHandlers>
<add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/>
</httpHandlers>
<compilation debug="false" targetFramework="4.0">
</compilation>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
</configuration>最后的问题就是:前台的这句 var mes = Default2.gets();
说Default2 未定义。