【发布时间】:2017-11-01 12:56:44
【问题描述】:
更新 3:
GetGrowers 调用的代码:
using AjaxControlToolkit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.ServiceModel.Web;
namespace AmericanApple
{
public partial class ReceivingStation : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
bcDataTextBox.Focus();
}
[ScriptMethod]
[WebMethod]
public static string[] GetGrowers(string prefixText, int count)
{
string[] growers = { "American Apple", "Lewis", "Grice" };
return growers;
}
}
}
更新 2:
我想我已经确定了问题所在。在 Chrome 开发者工具中查看“网络”选项卡时,我可以看到对 GetGrowers 的调用,并且在请求标头中,它要求application/json 格式,但在响应标头中,它返回text/html。所以下拉列表中的所有这些字符实际上是 html 中的整个页面。
在我的工作示例中,Auto CE 调用的响应标头是application/json。因此,无论出于何种原因,我的项目对此的响应格式不正确。我检查了 web.config 文件,没有发现我的工作示例和我正在处理的项目之间有任何差异。
更新:
Chrome 中正在发生的事情的图片:
原文:
我的 AutoCompleteExtender 无法工作。在 Chrome 和 FireFox 中,我的自动完成结果是一堆(随机?)字符。仅在 Internet Explorer 中,当我单击 TextBox 时,页面冻结,我的 Visual Studio 输出如下所示:
在评估代码中的第 39 行第 3 列抛出异常
0x800a1391 - JavaScript 运行时错误:“s”未定义
在 eval 代码中的第 37 行第 3 列抛出异常
0x800a1391 - JavaScript 运行时错误:“r”未定义
在 eval 代码中的第 31 行第 3 列抛出异常
0x800a1391 - JavaScript 运行时错误:“e”未定义
...并且一直这样下去。
我安装了最新的 AjaxControlToolkit:17.1.1。 我正在使用 VS Pro 2015 版本 14.0.25420.01 更新 3。 .NET 框架版本 4.7.02046
在我的 Site.Master 页面中我声明
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
在顶部和正文中我的脚本管理器:
<asp:ScriptManager runat="server" EnablePageMethods="true" EnablePartialRendering="true">
<Scripts>
<%--To learn more about bundling scripts in ScriptManager see http://go.microsoft.com/fwlink/?LinkID=301884 --%>
<%--Framework Scripts--%>
<asp:ScriptReference Name="MsAjaxBundle" />
<asp:ScriptReference Name="jquery" />
<asp:ScriptReference Name="bootstrap" />
<asp:ScriptReference Name="respond" />
<asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
<asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" />
<asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" />
<asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" />
<asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" />
<asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" />
<asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" />
<asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" />
<asp:ScriptReference Name="WebFormsBundle" />
<%--Site Scripts--%>
</Scripts>
</asp:ScriptManager>
在运行 AutoCompleteExtender 的页面上:
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<cc1:AutoCompleteExtender ID="AutoCompleteGrower" runat="server" TargetControlID="txtGrower"
MinimumPrefixLength="0" CompletionInterval="100" EnableCaching="true" UseContextKey="false"
ServiceMethod="GetGrowers" CompletionListCssClass="autocomplete_List" CompletionListItemCssClass="autocomplete_ListItem"
CompletionListHighlightedItemCssClass="autocomplete_HighlightedListItem" FirstRowSelected="true">
</cc1:AutoCompleteExtender>
我的文本框:
<asp:TableCell><asp:TextBox ID="txtGrower" runat="server" CssClass="form-control" AutoCompleteType="None"></asp:TextBox></asp:TableCell>
我没有在 SO 上找到具有相同错误的 AutoCompleteExtender 问题。我在这里想念什么?错误发生在我的 ServiceMethod 可以返回之前,我知道很多。
【问题讨论】:
-
很难找到错误的位置。您能否将StaticResources NuGet package 添加到您的项目中,这样脚本就不会被缩小?
-
我刚刚尝试安装 v17.1.1 和以前的版本,两次 VS 都冻结(不响应)。我在安装任何其他 NuGet 包时没有遇到问题。
-
对原帖进行了更新。
-
@MikhailTymchukDX 还有另一种安装 StaticResources 的方法吗?
-
您可以尝试将您的项目添加到the AJAX Control Toolkit solution并在本地调试。
标签: c# asp.net ajaxcontroltoolkit autocompleteextender