0

I am trying to implement an autocompleteextender ajax control in my website and its not working at all. Please help me out with this . Here is the code sample below.

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>   

Code behind

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

_ _ Public Class RClassAutoComplete Inherits System.Web.Services.WebService _ Public Function getrclass(ByVal PrefixText As String, ByVal count As Integer) As String() Dim items() As String items(0) = "one" items(1) = "oneeee" items(2) = "onedsgf" items(3) = "onettgdfsg" items(4) = "onedgdfgbvc" items(5) = "onerytretgfdsg" items(6) = "onergesrfgdf"

    Return items

End Function

Please let me know what mistake i have did here

Kumar
  • 58
  • 1
  • 8

1 Answers1

0

What worked for me was to have a tag to the script manager in the body of the master file.

<%@ 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>

Then in some page file that uses said master page you attach the extender to a field

<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" />

In mine, Ajax_methods.asmx, I have the following code.

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

And finally in the Ajax_methods.cs I have

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

It didn't work for me until all the little pieces were in place.