自动完成AJAX不工作 [英] AutoComplete AJAX Not Working

查看:208
本文介绍了自动完成AJAX不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 AutoCompleteExtender 从AjaxControlToolkit在文本框

I am using an AutoCompleteExtender from AjaxControlToolkit on a TextBox.

要简单地说,当我拖上我的文本框掉落 AutoCompleteExtender 工具,然后单击添加自动完成页面的方法,我得到以下错误:

To put it simply, when I drag and drop the AutoCompleteExtender tool on to my TextBox and then click on "Add AutoComplete page method", I get the following error:

无法创建页面的方法GetCompletionlist因为没有codeBehind或
  codeFILE被发现!

Cannot create page method "GetCompletionlist because no CodeBehind or CodeFile was found!

谷歌搜索错误后,我基本上是做了我自己的Web服务被称为AutoCompelte.asmx。下面是code该类:

After googling the error, I basically made my own web-service called AutoCompelte.asmx. Below is the code for that class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace AutoCompleteTest
{
    /// <summary>
    /// Summary description for AutoComplete
    /// </summary>
    [WebService(Namespace = "http://microsoft.com/webservices/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class AutoComplete : System.Web.Services.WebService
    {
        [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
        public static string[] GetCompletionList(string prefixText, int count, string contextKey)
        {
            // Create array of movies  
            string[] movies = { "Star Wars", "Star Trek", "Superman", "Memento", "Shrek", "Shrek II" };

            // Return matching movies  
            return (from m in movies where m.StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase) select m).Take(count).ToArray();
        }  
    }
}

当然,上面是伪数据....后来,我从数据库中获取数据。

Of course, the above is dummy data.... Later on, I shall be getting the data from a database.

和我Default.aspx的是这样的:

And my Default.aspx looks like this:

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
    From
<asp:TextBox ID="txtFrom" runat="server">
</asp:TextBox>  


<asp:AutoCompleteExtender runat="server" 
    ID="txtFrom_AutoCompleteExtender" 
    TargetControlID="txtFrom"
    ServiceMethod="GetCompletionList"
    ServicePath="AutoComplete.asmx"
    MinimumPrefixLength="2" 
    CompletionInterval="1000"
    EnableCaching="true"
    CompletionSetCount="20"
    DelimiterCharacters=";, :"
    ShowOnlyCurrentWordInCompletionListItem="true">
</asp:AutoCompleteExtender>

当我运行的网站....并输入文本框,什么都不会发生。没有扩展所示。即使我输入明星。

When I run the website....and type in the textbox, nothing happens. No Extender is shown. Even if I type "Star".

我是什么失踪,为什么我收到这个错误开头?

What am I missing and why was I getting that error at the beginning?

P.S。我在我的大学电脑,所以,我认为错误可能是由于我使用的网络类型。不知道。

P.S. I am on my University computers so, I think that error might be due to the type of network i am using. not sure.

任何帮助是非常HIGHLY HIGHLY AP preciated !!

Any help is HIGHLY HIGHLY HIGHLY appreciated!!

感谢。

推荐答案

我得到了它的工作。这是我如何固定它:

I got it working. This is how I fixed it:

我的项目是一个应用程序的网站在Visual Studio中。当我只是做了一个网站项目,它的所有工作完美....我不知道为什么,它只是做了。

My project was a "Website Application" in Visual Studio. When I simply made a "Website" project, it all worked perfectly.... I don't know why, it just did.

因此​​,如果其他人是否有相同的问题,尝试端口code到一个网站项目,而不是一个网站应用程序项目。

So if anyone else is having the same problem, try port the code over to a "Website" project rather than a "Website Application" project.

希望有所帮助。

这篇关于自动完成AJAX不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆