服务端代码: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 WebApplication3
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.LinkButton LinkButton1;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
Ajax.Utility.RegisterTypeForAjax(typeof(WebApplication3.WebForm1));
} [Ajax.AjaxMethod]
public string Test()
{
return "kyc";
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{    
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
}
}客户端代码:<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication3.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</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">
function Test1(){
WebForm1.Test(callback_Test1)
}

function callback_Test1(res){
alert(res.value);
}

</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<INPUT id="Button1" style="Z-INDEX: 101; LEFT: 256px; POSITION: absolute; TOP: 64px" type="button"
value="Button" onclick="Test1();return;">
<asp:LinkButton id="LinkButton1" style="Z-INDEX: 102; LEFT: 424px; POSITION: absolute; TOP: 64px"
runat="server">LinkButton</asp:LinkButton>
</form>
</body>
</HTML>
webconfig中已增加了
<system.web>

<httpHandlers>
<add verb="POST,GET" path="csharpwrapper/*.ashx" type="Ajax.PageHandlerFactory, Ajax" />
    </httpHandlers>....</system.web>

解决方案 »

  1.   

    出现 WebForm1未定义 不晓得问题出现在哪里?
      

  2.   

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>  <configSections>
        <sectionGroup name="ajaxNet">
          <section name="ajaxSettings" type="Ajax.AjaxSettingsSectionHandler, Ajax" />
          <section name="ajaxConverters" type="Ajax.AjaxConverterSectionHandler, Ajax" />
        </sectionGroup>
      </configSections>  <ajaxNet>
    <ajaxSettings>
    <commonAjax enabled="false" path="ajax.js" language="javascript" />
    <temporaryFiles path="~/images" deleteAfter="1" />
    <urlNamespaceMappings>
    <add namespace="CSharpSample.DemoMethods,CSharpSample" path="MyDemoMethods" />
    </urlNamespaceMappings>
    </ajaxSettings>
    <ajaxConverters>
    <remove type="Ajax.JSON.DateTimeConverter, Ajax" />
    <add type="CSharpSample.DateTimeConverter, CSharpSample" />
    </ajaxConverters>
      </ajaxNet>
      
      <system.web>    <httpHandlers>
    <add verb="POST,GET" path="csharpwrapper/*.ashx" type="Ajax.PageHandlerFactory, Ajax" />
        </httpHandlers>      <!--  DYNAMIC DEBUG COMPILATION
              Set compilation debug="true" to enable ASPX debugging.  Otherwise, setting this value to
              false will improve runtime performance of this application. 
              Set compilation debug="true" to insert debugging symbols (.pdb information)
              into the compiled page. Because this creates a larger file that executes
              more slowly, you should set this value to true only when debugging and to
              false at all other times. For more information, refer to the documentation about
              debugging ASP.NET files.
        -->
        <compilation 
             defaultLanguage="c#"
             debug="true"
        />    <!--  CUSTOM ERROR MESSAGES
              Set customErrors mode="On" or "RemoteOnly" to enable custom error messages, "Off" to disable. 
              Add <error> tags for each of the errors you want to handle.          "On" Always display custom (friendly) messages.
              "Off" Always display detailed ASP.NET error information.
              "RemoteOnly" Display custom (friendly) messages only to users not running 
               on the local Web server. This setting is recommended for security purposes, so 
               that you do not display application detail information to remote clients.
        -->
        <customErrors 
        mode="RemoteOnly" 
        />     <!--  AUTHENTICATION 
              This section sets the authentication policies of the application. Possible modes are "Windows", 
              "Forms", "Passport" and "None"          "None" No authentication is performed. 
              "Windows" IIS performs authentication (Basic, Digest, or Integrated Windows) according to 
               its settings for the application. Anonymous access must be disabled in IIS. 
              "Forms" You provide a custom form (Web page) for users to enter their credentials, and then 
               you authenticate them in your application. A user credential token is stored in a cookie.
              "Passport" Authentication is performed via a centralized authentication service provided
               by Microsoft that offers a single logon and core profile services for member sites.
        -->
        <authentication mode="Windows" />  <!--  AUTHORIZATION 
              This section sets the authorization policies of the application. You can allow or deny access
              to application resources by user or role. Wildcards: "*" mean everyone, "?" means anonymous 
              (unauthenticated) users.
        -->    <authorization>
            <allow users="*" /> <!-- Allow all users -->
                <!--  <allow     users="[comma separated list of users]"
                                 roles="[comma separated list of roles]"/>
                      <deny      users="[comma separated list of users]"
                                 roles="[comma separated list of roles]"/>
                -->
        </authorization>    <!--  APPLICATION-LEVEL TRACE LOGGING
              Application-level tracing enables trace log output for every page within an application. 
              Set trace enabled="true" to enable application trace logging.  If pageOutput="true", the
              trace information will be displayed at the bottom of each page.  Otherwise, you can view the 
              application trace log by browsing the "trace.axd" page from your web application
              root. 
        -->
        <trace
            enabled="true"
            requestLimit="100"
            pageOutput="false"
            traceMode="SortByTime"
    localOnly="true"
        />    <!--  SESSION STATE SETTINGS
              By default ASP.NET uses cookies to identify which requests belong to a particular session. 
              If cookies are not available, a session can be tracked by adding a session identifier to the URL. 
              To disable cookies, set sessionState cookieless="true".
        -->
        <sessionState 
                mode="InProc"
                stateConnectionString="tcpip=127.0.0.1:42424"
                sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
                cookieless="false" 
                timeout="20" 
        />    <!--  GLOBALIZATION
              This section sets the globalization settings of the application. 
        -->
        <globalization 
                requestEncoding="utf-8" 
                responseEncoding="utf-8" 
       />
       
     </system.web></configuration>
      

  3.   

    上面写错了,是下面这个webconfig.<?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        
      <system.web>

    <httpHandlers>
    <add verb="POST,GET" path="csharpwrapper/*.ashx" type="Ajax.PageHandlerFactory, Ajax" />
        </httpHandlers>

        <!--  动态调试编译
              设置 compilation debug="true" 以启用 ASPX 调试。否则,将此值设置为
              false 将提高此应用程序的运行时性能。
              设置 compilation debug="true" 以将调试符号(.pdb 信息)
              插入到编译页中。因为这将创建执行起来
              较慢的大文件,所以应该只在调试时将此值设置为 true,而在所有其他时候都设置为
              false。有关更多信息,请参考有关
              调试 ASP.NET 文件的文档。
        -->
        
        <compilation 
             defaultLanguage="c#"
             debug="true"
        />    <!--  自定义错误信息
              设置 customErrors mode="On" 或 "RemoteOnly" 以启用自定义错误信息,或设置为 "Off" 以禁用自定义错误信息。 
              为每个要处理的错误添加 <error> 标记。          "On" 始终显示自定义(友好的)信息。
              "Off" 始终显示详细的 ASP.NET 错误信息。
              "RemoteOnly" 只对不在本地 Web 服务器上运行的
               用户显示自定义(友好的)信息。出于安全目的,建议使用此设置,以便 
               不向远程客户端显示应用程序的详细信息。
        -->
        <customErrors 
        mode="RemoteOnly" 
        />     <!--  身份验证 
              此节设置应用程序的身份验证策略。可能的模式是 "Windows"、 
              "Forms"、 "Passport" 和 "None"          "None" 不执行身份验证。 
              "Windows" IIS 根据应用程序的设置执行身份验证 
                (基本、简要或集成 Windows)。在 IIS 中必须禁用匿名访问。
              "Forms" 您为用户提供一个输入凭据的自定义窗体(Web 页),然后 
               在您的应用程序中验证他们的身份。用户凭据标记存储在 Cookie 中。
              "Passport" 身份验证是通过 Microsoft 的集中身份验证服务执行的,
               它为成员站点提供单独登录和核心配置文件服务。
        -->
        <authentication mode="Windows" />  <!--  授权 
               此节设置应用程序的授权策略。可以允许或拒绝不同的用户或角色访问
              应用程序资源。通配符: "*" 表示任何人,"?" 表示匿名
              (未经身份验证的)用户。
        -->    <authorization>
            <allow users="*" /> <!-- 允许所有用户 -->
                <!--  <allow     users="[逗号分隔的用户列表]"
                                 roles="[逗号分隔的角色列表]"/>
                      <deny      users="[逗号分隔的用户列表]"
                                 roles="[逗号分隔的角色列表]"/>
                -->
        </authorization>    <!--  应用程序级别跟踪记录
              应用程序级别跟踪为应用程序中的每一页启用跟踪日志输出。
              设置 trace enabled="true" 可以启用应用程序跟踪记录。如果 pageOutput="true",则
              在每一页的底部显示跟踪信息。否则,可以通过浏览 Web 应用程序
               根目录中的 "trace.axd" 页来查看
              应用程序跟踪日志。
        -->
        <trace
            enabled="false"
            requestLimit="10"
            pageOutput="false"
            traceMode="SortByTime"
    localOnly="true"
        />    <!--  会话状态设置
              默认情况下,ASP.NET 使用 Cookie 来标识哪些请求属于特定的会话。
              如果 Cookie 不可用,则可以通过将会话标识符添加到 URL 来跟踪会话。
             若要禁用 Cookie,请设置 sessionState cookieless="true"。
        -->
        <sessionState 
                mode="InProc"
                stateConnectionString="tcpip=127.0.0.1:42424"
                sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
                cookieless="false" 
                timeout="20" 
        />    <!--  全球化
              此节设置应用程序的全球化设置。
        -->
        <globalization 
                requestEncoding="utf-8" 
                responseEncoding="utf-8" 
       />
       
     </system.web></configuration>
      

  4.   

    <add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/>
      

  5.   

    老大,我的已经加了呀?我运行下载下来的sample可以执行的,放到我的程序里就是不行,真是怪事的。
      

  6.   

    path="ajax/*.ashx"
    你改成这样试试。
      

  7.   

    这个地方是public class WebForm1 : System.Web.UI.Page
    这个地方你引用的是Inherits="WebApplication3.WebForm1" %>
    如果想正常两种方法:
    1.将public class WebForm1 : System.Web.UI.Page改为public class WebApplication3.WebForm1 : System.Web.UI.Page
    2.将Inherits="WebApplication3.WebForm1" %>改为Inherits="WebForm1" %>
      

  8.   

    补充:这个地方Inherits="WebApplication3.WebForm1" 是让写类的名字,你这里类的名字是WebForm1所以不能这么写,不然就会出现你所遇到的问题。
      

  9.   

    在<system.web> 中加入<httpHandlers>
          <add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/>
     </httpHandlers> private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    Ajax.Utility.RegisterTypeForAjax(typeof(WebApplication3.WebForm1));
    }
    這個地方WebForm1有沒有變色啊?變了色的話應該可以的。
      

  10.   

    我试过了,还是不行呀,按道理应该没有问题的,怪就怪,我用他原来的sample,可以用的。我觉得代码和sample里面的代码一样的。
      

  11.   

    不是有demo代码吗,还有一步步来的教程,怎么会错呢
    如果还错就别用这家的了,用最原始的ajax吧
      

  12.   

    打开demo,运行没问题的,不晓得妈妈的,我的站点就有问题的?
      

  13.   

    求助:我把下面的内容已经引入我的Ajax网页,可是他还报错:无法识别的配置节 ajaxNet
    (我的是Ajax网页,不是一般的Asp.net网页)
    <?xml   version= "1.0 "   encoding= "utf-8 "   ?> 
    <configuration>     <configSections> 
            <sectionGroup   name= "ajaxNet "> 
                <section   name= "ajaxSettings "   type= "Ajax.AjaxSettingsSectionHandler,   Ajax "   /> 
                <section   name= "ajaxConverters "   type= "Ajax.AjaxConverterSectionHandler,   Ajax "   /> 
            </sectionGroup> 
        </configSections>     <ajaxNet> 
    <ajaxSettings> 
    <commonAjax   enabled= "false "   path= "ajax.js "   language= "javascript "   /> 
    <temporaryFiles   path= "~/images "   deleteAfter= "1 "   /> 
    <urlNamespaceMappings> 
    <add   namespace= "CSharpSample.DemoMethods,CSharpSample "   path= "MyDemoMethods "   /> 
    </urlNamespaceMappings> 
    </ajaxSettings> 
    <ajaxConverters> 
    <remove   type= "Ajax.JSON.DateTimeConverter,   Ajax "   /> 
    <add   type= "CSharpSample.DateTimeConverter,   CSharpSample "   /> 
    </ajaxConverters> 
        </ajaxNet>