Last post Jul 08, 2014 02:11 AM by CatoTheElder
Jul 04, 2014 01:33 PM|CatoTheElder|LINK
I have been at this for quite some time. I cannot get a textbox to list auto-complete suggestions, whatever I try. The folks at MSDN suggested I post here. Please see the original thread, here: http://social.msdn.microsoft.com/Forums/vstudio/en-US/38b97b18-3413-4cd7-8df6-095fea8c82f7/autocomplete-from-custom-source-6-hours-still-not-working?forum=vbgeneral
.Net Framework 4.5
AJAX Control Toolkit 126.96.36.1993 (2013)
Visual Studio 2013
VB.NET (ASP.NET 4.5)
MS SQL 2012 (eventually)
End goal is to pull a subset of data from a SQL table, and have it displayed as auto-complete suggestions. The database part is simple enough... it all seems simple enough, it just doesn't work. No errors or warnings, just no auto-complete suggestions at all.
From what I've read, you have to manually add a Class and Web Service/Method. I've tried with, and without that, no result visible either way.
Any advice / examples would be greatly appreciated.
Resources Used (failed):
(and many more)
Current Code (One of many attempts)
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="nseac.aspx.vb" Inherits="easyac8.nseac" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="TextBox1" Enabled="True" ServicePath="AutoComplete.asmx" ServiceMethod="GetWordList" MinimumPrefixLength="1" />
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
Public Class WebService1
<System.Web.Services.WebMethod()> Public Function GetWordList(ByVal prefixText As String, ByVal count As Integer) As String()
Dim r(1) As String
r(0) = "Testing0"
r(1) = "Testing1"
Return r 'breakpoint here, has never been hit
Jul 06, 2014 10:31 PM|Fuxiang Zhang - MSFT|LINK
Welcome to asp.net forum!
Your code looks fine in my side, what I suggest you take a look below points.
see whether it shows you matedata.
# Make sure your asmx web service and aspx page in the same directory at your project.
# Besides, for how AutoCompleteExtender works and for how to use it, I suggest you follow below tutorials document.
Hope that helps, thanks.
Jul 08, 2014 02:11 AM|CatoTheElder|LINK
Thanks for the reply Fuxiang Zhang .... unfortunately the code was not fine. I've almost got this figured out.
This is what I've got now, cobbled together from various resources, and trial and error over a few days:
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox> <asp:AutoCompleteExtender ID="aceTxtSearch" runat="server" Enabled="True" ServiceMethod="GetWordList"
7. Create your own web method to handle collecting and returning the data (right click project in solution explorer -> Add -> Web Service (asmx). Name this file as you'd like, but be sure the ServicePath property above matches,
the class matches the file name, and the ServiceMethod property above matches the function name. Ex:
Imports System.Web.ServicesImports System.Web.Services.ProtocolsImports System.ComponentModel 'To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.<System.Web.Script.Services.ScriptService()> _<System.Web.Services.WebService(Namespace:="<your domain here>")> _<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _<ToolboxItem(False)> _Public Class asmxAcetxtSearch Inherits System.Web.Services.WebService <WebMethod()> _Public Function GetWordList(ByVal prefixText As String, ByVal count As Integer) As String() Dim AutoCompleteList as string() AutoCompleteList(0) = "AutoComplete Option 1"AutoCompleteList(1) = "AutoComplete Option 2"Return AutoCompleteList End FunctionEnd Class
8. Ensure the following is in your web.config:
<httpHandlers> <remove verb="*" path="*.asmx"/> <add verb="*" path="*.asmx" type="System.Web.Script.Services.ScriptHandlerFactory" validate="false"/></httpHandlers>
This works on my workstation, dev environment, and 2 of 3 websites I'm currently running in production. Still investigating why the 3rd isn't working... possibly something to do with SSL, although URLRewrite doesn't effect it, when done properly :)
Despite what you've probably read, do not use the autocomplete link, they error out, and are completely useless.
AutoComplete works fine in both an update panel, and a table cell. :)
If anyone could help with the HTTPS / required / disallowed web server configuration, that would be awesome.
Also, could we please make this a sticky, or add it to the FAQs, or something along those lines? I have been through literally hundreds of outdated/incorrect posts and tutorials on this topic, and it would be great to save others the trouble.