首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ASP.NET 2.0 C# AjaxPro RegisterTypeForAjax

ASP.NET 2.0 C# AjaxPro RegisterTypeForAjax
EN

Stack Overflow用户
提问于 2010-04-27 01:31:20
回答 2查看 4.5K关注 0票数 1

我想知道RegisterTypeForAjax是不是工作不正常。我得到了下面代码块末尾的错误信息。示例来自这里:http://www.ajaxtutorials.com/asp-net-ajax-quickstart/tutorial-introduction-to-ajax-in-asp-net-2-0-and-c/

你知道为什么我会得到这个错误吗?谢谢。

ASP .NET 2.0 C#

以下是代码隐藏:

代码语言:javascript
复制
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using AjaxPro;


namespace WebApplication1
{
    public partial class Ajax_CSharp : System.Web.UI.Page
    {
        protected override void OnInit( EventArgs e )
        {
            base.OnInit( e );
            Load += new EventHandler( Page_Load );
        }

        protected void Page_Load( object sender, EventArgs e )
        {
            Utility.RegisterTypeForAjax( typeof( Ajax_CSharp ) );
        }

        [ AjaxMethod( HttpSessionStateRequirement.ReadWrite ) ]
        public string GetData()
        {
            // method gets a row from the db and returns a string.
        }
}

下面是ASPX页面:

代码语言:javascript
复制
<%@ Page Language="C#" AutoEventWireup="false" CodeBehind="Default.aspx.cs" Inherits="WebApplication1.Ajax_CSharp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
       function GetData()
       {
          var response;
          Ajax_CSharp.GetData( GetData_CallBack );
       }

       function GetData_CallBack( response )
       {
          var response = response.value;

          if ( response == "Empty" )
          {
             alert( "No Record Found." );
          }
          else if ( response == "Error" )
          {
             alert( "An Error Occurred in Accessing the Database !!!" );
          }
          else
          {
             var arr = response.split( "~" );
             var empID = arr[0].split( "," );
             var empName = arr[1].split( "," );

             document.getElementById( 'dlistEmployee' ).length = 0;

             for ( var i = 0; i < empID.Length; i++ )
             {
                var o = document.createElement( "option" );
                o.value = empID[i];
                o.text = empName[i];
                document.getElementById( 'dlistEmployee' ).add( o );
             }
          }
       }

       function dodisplay()
       {
          var selIndex = document.getElementById( "dlistEmployee" ).selectedIndex;
          var empName = document.getElementById( "dlistEmployee" ).options( selIndex ).text;
          var empID = document.getElementById( "dlistEmployee" ).options( selIndex ).value;

          document.getElementById( "lblResult" ).innerHTML = "You have selected " + empName + " (ID: " + empID + " )";
       }

    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div style="text-align: center;">
        <input id="btnGetData" 
               onclick="GetData();" 
               type="button" 
               value="To Get Employee Data From DB" style="width: 203px" />
        &nbsp;&nbsp;
        <asp:DropDownList id="dlistEmployee" OnTextChanged="dodisplay();" />
        <asp:Label id="lblResult" runat="server" Text="No Record Selected" />
    </div>
    </form>
</body>
</html>

运行它并单击按钮,我会得到这个错误:

网页错误详细信息

用户代理: Mozilla/4.0 (兼容;MSIE8.0;Windows NT 5.1;Trident/4.0;.NET CLR 1.1.4322;.NET CLR 2.0.50727;.NET CLR 3.0.4506.2152;.NET CLR 3.5.30729;InfoPath.2;MS-RTC 8)时间戳: Mon,26 Apr 2010 17:22:44 UTC

消息:'Ajax_CSharp‘未定义行: 13字符: 11代码:0 URI:http://localhost:4678/Default.aspx

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-04-27 01:47:13

尝试使用全名。

在这种情况下,请更改:

代码语言:javascript
复制
Ajax_CSharp.GetData( GetData_CallBack );

代码语言:javascript
复制
WebApplication1.Ajax_CSharp.GetData( GetData_CallBack );

现在发生的情况是,页面根本不知道Ajax_CSharp是什么。在使用AjaxPro时,您应该始终使用类的FullName,即Namespace.ClassName

票数 1
EN

Stack Overflow用户

发布于 2015-08-19 02:40:27

对于每个仍然有这个问题的人。您需要在页面中添加一个< form > html标记。不需要包含任何全名标签,也不需要在de form中包含任何输入。

代码语言:javascript
复制
<form id="Form1" method="post" runat="server">

验证您是否已经在web.config中添加了处理程序

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2715515

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档