Autocompleteextender无法在.net目标框架3.5中工作

时间:2013-03-27 17:46:32

标签: asp.net-ajax autocompleteextender

我正在尝试在我的网站中实现autocompleteextender ajax控件,而它根本不工作。这个你能帮我吗 。 以下是代码示例。

ASPX:

    <cc3:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">     
</cc3:ToolkitScriptManager>    
<asp:TextBox ID="txtContactsSearch" runat="server" ></asp:TextBox>
<cc3:AutoCompleteExtender ServiceMethod="getrclass"
servicepath="RClassAutoComplete.asmx"    
MinimumPrefixLength="2"    
CompletionInterval="100" EnableCaching="true" CompletionSetCount="10"   
TargetControlID="txtContactsSearch"
ID="AutoCompleteExtender1" runat="server" 
UseContextKey="True">
</cc3:AutoCompleteExtender>   

背后的代码

<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _

_  _ 公共类RClassAutoComplete     继承System.Web.Services.WebService      _     公共函数getrclass(ByVal PrefixText As String,ByVal count as Integer)As String()         Dim items()As String         items(0)=&#34; one&#34;         items(1)=&#34; oneeee&#34;         items(2)=&#34; onedsgf&#34;         items(3)=&#34; onettgdfsg&#34;         items(4)=&#34; onedgdfgbvc&#34;         items(5)=&#34; onerytretgfdsg&#34;         items(6)=&#34; onergesrfgdf&#34;

    Return items

End Function

请让我知道我在这里做了什么错误

1 个答案:

答案 0 :(得分:0)

对我来说有用的是在主文件正文中为脚本管理器添加标记。

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="AjaxControlToolkit" %>

...

<AjaxControlToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
    <Services>
            <asp:ServiceReference Path="~/Ajax_methods.asmx" />
    </Services>
</AjaxControlToolkit:ToolkitScriptManager>

然后在使用所述母版页的某个页面文件中,将扩展程序附加到字段

<asp:UpdatePanel ID="customerAddress" runat="server">
<AjaxControlToolkit:AutoCompleteExtender ID="aceCustName" runat="server" DelimiterCharacters="" Enabled="True"
        TargetControlID="txtCustomerName" ServicePath="~/Ajax_methods.asmx" ServiceMethod="GetCompletionList"
        MinimumPrefixLength="1" CompletionSetCount="20" ContextKey="test" UseContextKey="True" />

在我的Ajax_methods.asmx中,我有以下代码。

<%@ WebService Language="C#" CodeBehind="~/App_Code/Ajax_methods.cs" Class="Ajax_methods" Debug="true"%>

最后在Ajax_methods.cs中我有

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public string[] GetCompletionList(string prefixText, int count, string contextKey)

直到所有小件都到位后,它才对我有用。