aspx页面:
单击按钮事件响应 AjaxAdd()函数:function AjaxAdd()
{
Con= "Ajax send";
alert(Con);
net.test.GetReturnCode(Con, IsAjaxAdd_callback);
alert(Con+"哈哈!");
}function IsAjaxAdd_callback(res)
{
alert(res.value);
}=========
aspx.cs:
[AjaxPro.AjaxMethod]
public string GetReturnCode(string aa)
{
  if (aa =="Ajax send")
  {
    return "receive Ajax!";
   }
  else
  {
    return "no way!";
  }
}
脚本执行到“net.test.GetReturnCode(Con, IsAjaxAdd_callback);”这里的时候出错了。。怎么回事呢?

解决方案 »

  1.   

    是否添加了以下代码呢
    private void Page_Load(object sender, System.EventArgs e)
    {
    if(!IsPostBack)
    {
    Ajax.Utility.RegisterTypeForAjax(typeof(test));
    }
    }
      

  2.   

    在脚本的时候就执行错误了error page呵呵
    因为我在“net.test.GetReturnCode(Con, IsAjaxAdd_callback);”前后都做了alert判断执行进度。在后台的public string GetReturnCode(string aa)里面做了断点,但net.test.GetReturnCode(Con, IsAjaxAdd_callback);还未执行到断点就报error page了
    所以估计是net.test.GetReturnCode(Con, IsAjaxAdd_callback);写错了还是什么的
      

  3.   

    private void Page_Load(object sender, System.EventArgs e)
    {
      Ajax.Utility.RegisterTypeForAjax(typeof(test));
      if(!IsPostBack)
      {
        //......
      }
    }
      

  4.   

    其实这样写就可以了...test.GetReturnCode(Con, IsAjaxAdd_callback);
    问下:
    <%@ Page language="c#"   Inherits="net.test" %>
    是这样写的吗
      

  5.   

    你先这样写..可以得到值吗?
    test.GetReturnCode(Con).value;
      

  6.   

    是的.
    后台的
    namespace net
    {
      public class test : System.Web.UI.Page
      {
        ....前台:
    <%@ Page language="c#" Codebehind="net.aspx.cs" AutoEventWireup="false" Inherits="net.test" %>
      

  7.   

    不是很明白
    test.GetReturnCode(Con).value;
    怎么得到值?
    我试了,但似乎程序没去到后台执行。
      

  8.   

    web.config写上了  <httpHandlers>
    <add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/>
    </httpHandlers>吗
      

  9.   

    我觉得是把名称改下...net.test
    function getInfo()
    {
    WebEmail.WebForm2.GetMsg(GetMsg_callback);
    }
    function  GetMsg_callback(response)
    {
    var det= response.value;
    if(det!=null && det.Tables!=null && typeof(det)=="object")
    {
    var dt="您有"+det.Tables[0].Rows.length + "封消息";
    var msg=det.Tables[0].Rows[0].email_text;
    我也是这样写的...貌似一点错都没有
      

  10.   

    难道是因为我用的是.net 2003的原因?
      

  11.   

    贴一个另外写的完整的测试,但也没通过:
    sapx.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 fortest
    {
    /// <summary>
    /// WebForm1 的摘要说明。
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {

    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    AjaxPro.Utility.RegisterTypeForAjax(typeof(WebForm1));
    } [AjaxPro.AjaxMethod]
    public string GetReturnCode(string Con)
    {
    // string Con;
    // Con ="Ajax send";
    if (Con =="Ajax send")
    {
    return "receive Ajax!";
    }
    else
    {
    return "no way!";
    }
    } #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
    }
    }=======================
    aspx:<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="fortest.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=jscript>
    var Con;
    function AjaxAdd()
    {
    Con= "Ajax send";
    alert(Con);
    WebForm1.GetReturnCode("Ajax",IsAjaxAdd_callback);
    //WebForm1.GetReturnCode(Con).value;
    alert(Con+"哈哈!");
    } function IsAjaxAdd_callback(response)
    {
    var aa = response.value;
    alert(aa);
    } </script>
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    &nbsp;<INPUT style="Z-INDEX: 101; LEFT: 264px; POSITION: absolute; TOP: 112px" type="button"
    value="Button" onclick="AjaxAdd();">
    </form>
    </body>
    </HTML>============
    web.config  <system.web>
      
      <httpHandlers> 
      <add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro"/> 
      </httpHandlers>    <!--  动态调试编译
              设置 compilation debug="true" 以启用 ASPX 调试。否则,将此值设置为
              false 将提高此应用程序的运行时性能。
              设置 compilation debug="true" 以将调试符号(.pdb 信息)
              插入到编译页中。因为这将创建执行起来
              较慢的大文件,所以应该只在调试时将此值设置为 true,而在所有其他时候都设置为
              false。有关更多信息,请参考有关
              调试 ASP.NET 文件的文档。
        -->