Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi,

My AutoCompleteExtender is not firing I can't figure out what is wrong with my code please someone help me. Thanks.
ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AutoCompleteWebService.aspx.cs" Inherits="WebService1.AutoCompleteWebService" %>

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

<!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></title>

</head>
<body>
    <form id="form1"  runat="server">
    <div>
        <asp:ScriptManager ID="sm1" runat="server" EnablePartialRendering="false" />                               
        <ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender1" TargetControlID="txtFileName" ServiceMethod="GetSuggestions"
            ServicePath="~/FileService.asmx" MinimumPrefixLength="1"  runat="server" />

        <asp:TextBox ID="txtFileName" runat="server"></asp:TextBox>
        
    </div>
    </form>
</body>
</html>


Here's my webservice:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.IO;

namespace WebService1
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class FileService : System.Web.Services.WebService
    {
        [WebMethod]
        public string[] GetSuggestions(string prefixText, int count)
        {
            DirectoryInfo dir = new DirectoryInfo("c:\\windows");
            return dir
                .GetFiles()
                .Where(f => f.Name.StartsWith(prefixText))
                .Select(f => f.Name)
                .ToArray();
        }
    }
}
Posted
Updated 4-Mar-12 22:26pm
v2

use Toolkitscript manager instead of scriptmanager.
 
Share this answer
 
v2
Comments
akosidab 5-Mar-12 4:14am    
Hi,

I have change it to ajaxToolkit:ToolkitScriptManager but still the same, it does not fire. But when i call the webservice on page load it is okay:


protected void Page_Load(object sender, EventArgs e)
{
FileService fService = new FileService();
string[] st = fService.GetSuggestions("s", 1);
}
Refer my article, might guide you
Using Ajax AutoCompleteExtender for autosuggest[^]
 
Share this answer
 
Comments
akosidab 5-Mar-12 4:31am    
I will check your article. Thanks :)
Hi Friends,

Thanks for your help. I have found the solution :D

I just uncomment the below script in the webservice asmx file.

C#
[System.Web.Script.Services.ScriptService]
 
Share this answer
 
The most convenient way to use autoCompleteextender with textbox is to right click on the textbox and add extender.From the Dialog Choose the AutoCompleteExtender and Ok.
Then Again right click and say ADD AutoCompletePageMethod.A Function will automatically be added to the.cs file.Add the desired code and see it runs...................
 
Share this answer
 
Comments
Member 9873093 8-Aug-15 4:22am    
This doesnt work. The autocomplete extender is not even listed

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900