[How Do I:] Use the ASP.NET AJAX AutoComplete Control

Please install Silverlight or click download to watch video locally.

The AutoComplete extender control from the ASP.NET AJAX Control Toolkit provides real-time suggestions to the user as he or she types in a text box on the Web page, where the list of suggestions is obtained by an asynchronous call to a Web service on the server.

Presented by Joe Stagner

Duration: 7 minutes, 7 seconds

Date: 20 March 2007

Watch    Video   |   Download    Video   |   VB Code    C# Code

Video downloads: WMV  |  Zune  |  iPod  |  PSP  |  MPEG-4  |  3GP

Audio downloads: AAC  |  WMA  |  MPEG-4  |  MPEG-3  |  MPEG-2

Comments : 82

Leave a Comment

jorge08 : On May 11, 2008 8:05 PM said:

Hi Joe, maybe you have a sample about this control using a database?

warrenvt : On June 02, 2008 1:50 PM said:

Hi Joe,

  I have an external web service that has been created for me to allow me access to a db. How can I use the AJAX to connect to this web service?

Gabriel82 : On June 07, 2008 8:44 AM said:

Jorge08 this is a small example with Access Database:

If (count = 0) Then

           count = 10

       End If

       Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("App_Data/ExpImpdb.mdb") & ";"

       Dim adp As New System.Data.OleDb.OleDbDataAdapter("select * from cars WHERE RecMerk Like '" & prefixText & "%' ", strConn)

       Dim dt As New System.Data.DataTable

       adp.Fill(dt)

       Dim items As New List(Of String)

       For i As Integer = 0 To dt.Rows.Count

           Dim datafile

           datafile = UCase(dt.Rows(i).Item("RecMerk"))

           i += 1

           items.Add(datafile)

       Next

       Return items.ToArray()

Sabeltann : On June 20, 2008 7:38 AM said:

Thanks Joe! I've wanted to try making an AJAX control like this for a while, but always thought it'd be more complex - you made it look easy.

From a beginner's viewpoint it wasn't obvious to me that when creating the webmethod, you can change the webmethod name as you like but the parameter names _must_ be prefixText and count (but maybe that's me being dumb)

It seems pretty easy to hook this up to a database using LINQ. If it's of any help, here's my code to query product names in Northwind, (assumes you've already made the linq to northwind class)

[WebMethod]

public string[] GetCompletionList(string prefixText, int count)

{

 // OBS! In real world, initialize this someplace else

 NorthwindDataContext Db = new NorthwindDataContext();

 var matches = from p in Db.Products

 where p.ProductName.StartsWith(prefixText)

 select p.ProductName;

 return matches.ToArray<string>();

}

sudheshna : On July 09, 2008 6:59 AM said:

Hi Joe,

I tried the code and is working fine but when I implemented URL rewriting its displaying a js error 'Syntax error' and the auto complete is not working its displaying results as undefined. If I remove the code

   <Services>

       <asp:ServiceReference Path="AutoComplete.asmx" />

   </Services>

</asp:ScriptManager>

there is no js error. I'm using C# and the auto complete text box is filled from DB. How can I solve this issue. Please help.

Thanks

Scorpiogenie : On July 11, 2008 10:40 PM said:

Hi Joe, I just wanted to say thanks. I’m interning with Goldman Sachs- Tech Division. Your videos have saved my life on numerous occasions. You are appreciated.

Jagarm : On July 17, 2008 2:01 PM said:

Hello Joe,

I have downloaded your VB code and try to run it on my computer, it does work in firefox but doesn't work in IE6 and up. The example about the autocomplete that is on Ajax Toolkit live page works with all platform. Any suggestion here?

Thanks

Jagar,

dummies2 : On July 18, 2008 2:24 PM said:

when i tried to use this example and get info out of my database it keeps telling me that my variable.toarray is wrong and gives me an error of type'1-dimensional array of string cannot be converted to string??? why is that?

here is my code please help.

Dim dtst As DataTable

       Dim sqlconnection As SqlConnection = New SqlConnection("connectionstring")

       Dim objcmd As SqlCommand = New SqlCommand("select namefrom students where name like '" + prefixTex + "%' ", sqlconnection)

       sqlconnection.Open()

       Dim sqladpt As SqlDataAdapter = New SqlDataAdapter

       sqladpt.SelectCommand = objcmd

       sqladpt.Fill(dtst)

       Dim cntname As List(Of String)

       For i As Integer = 0 To dtst.Rows.Count

           Dim datafile

           datafile = UCase(dtst.Rows(i).Item("description"))

           i += 1

           cntname.Add(datafile)

       Next

       Return cntname.ToArray

thank you in advnace

dummies2 : On July 18, 2008 2:26 PM said:

there should be a space between name and form but the error is from cntname.toarray.

dummies2 : On July 18, 2008 2:27 PM said:

sorry i was typing too fast the line

dtatfile=ucase(dtst.rows(i).item("description")

should be

dtatfile=ucase(dtst.rows(i).item("name")

dummies2 : On July 18, 2008 3:13 PM said:

got it there was a mistake on the public function (prefixtex as string) as string() but the textbox doesnt work. it doesn't autocomplete

mdasraful.islam : On July 21, 2008 1:34 AM said:

hi,

how can i show data in autocomplete list from northwind database in C#.I am a novice programmer.

gopikrishnag : On July 21, 2008 7:47 AM said:

Hi ,

Video is excellent. i want key/value pair, for example, if i select country name and value stored in the hidden field.

please let me how can i achive this.

Thanks

Gopi

mdasraful.islam : On July 21, 2008 11:04 PM said:

Hi Joe, maybe you have a sample about this control using a database from C# code? Please help me.

bill32 : On July 22, 2008 11:34 AM said:

Hi,

I ported the code to my WebApp and it works as long as I enter the full url including port number (localhost/AutoComplete.asmx) as the ServicePath Attribute for the AutoComplete Control. Is it possible to let the webservice run on a specified port number, or how did you manage to ommit the portnumber in your examples?

bill

bioscan : On July 23, 2008 7:00 AM said:

hey gopikrishnag,

i had the same issue with key/value.

look here, it's easy:

blogs.msdn.com/.../how-to-use-a-key-value-pair-in-your-autocompleteextender.aspx

grahams : On August 06, 2008 10:28 AM said:

I've tried this using Visual Studio 2005 (with the AJAX 1.0 extensions for ASP.net 2.0 installed on my server). Browsing with IE6.0.2 sp2.

I've followed the steps in the video, but I get an annoyingly vague JavaScript error on my .aspx page saying, simply that:

'Sys' is undefined.

When I view the source of the .aspx page, I find that the Sys assembly is indeed required, and it seems to initialise my ScriptManager, which contains the details of the WebService I've created. It looks like it's fundamental to the method, but the CDATA section seems to be auto-generated.

//<![CDATA[

Sys.WebForms.PageRequestManager._initialize('ScriptManager1 ', document.getElementById('form1'));

Sys.WebForms.PageRequestManager.getInstance()._updateContro ls([], [], [], 90);

//]]>

So my question is, how can I satisfy this auto-generated dependency on Sys.WebForms.PageRequestManager to make my page load without errors, and therefore be able to AutoComplete the text box?

graham

cv_vikram : On August 06, 2008 2:46 PM said:

Very good tutorial.....thanks

viswesh : On August 07, 2008 3:48 AM said:

hi joe,i have done what you said in the video,but i am not geting output.webservice is running fine, is it getting values .but in .aspx i am not getting the output ...what shiould i do now??.......thanx in advance.

JRLiem : On August 11, 2008 2:28 AM said:

The video is excellent.

Is it possible to add an argument in the web service method?

How to pass value to the additional argument?

thank you

umayxa3 : On August 11, 2008 5:02 PM said:

I finally got my SubSonic/Stored Procedure call to work with the Ajax AutoComplete:

   public string[] GetCompletionList(string prefixText, int count)

   {

       if (count == 0)

       {

           count = 10;

       }

       List<string> items = new List<string>(count);

       SubSonic.StoredProcedure sp = new SubSonic.StoredProcedure("GetAllInfo");

       sp.Command.AddParameter("@pIn", "RIGHT");

       sp.Command.AddParameter("@sSearch", prefixText);

       DataSet ds = sp.GetDataSet();

       foreach (DataRow dr in ds.Tables[0].Rows)

       {

           items.Add(dr[0].ToString());

       }

       return items.ToArray();

   }

ybechar : On August 12, 2008 3:51 PM said:

Hi Joe,

Great demo. Of course I got some problems with the whole AutoComplete extender.

I am try to use it in two places:

1. A master page and

2. on a web user control

I have followed your example step by step.  When I create a new project and run it, it does run fine.

The problem is when I try to implement it on my "real" project.

On the bottom of the browser (IE 7) I get the "warning message" when I double click on it it give me the following message:

"Error: Sys.ArgumentUndefineException: Value cannot be undefined. Paramenter Name: type"

Any ideas what is going on in here????

I would appreciate any help since I have been trying to add this functionality for a while now.....

Thanks in advance

dmrlady : On August 14, 2008 4:04 PM said:

Hi I try this program and it works fine. Accept when I am using a database file with information. The field that I am trying to load is a sql field with nvar(9) but it has only numbers. When I do Return items.ToArray only the items that do not start with zeros are loaded to the array. I look at the field before it is added to the array and it has the leading zero, but it does not get returned. I want all fields loaded even the ones with the zeros. Please help.  Diana

kbob : On August 17, 2008 7:42 AM said:

Hi

Im trying to use this control on a webpart (user control) using a static method [webmethod], for some reason this does not work, the event never triggers. Is there a known issue about this extender and a user control or an issue implementing the method of the extender in a non webservise method???

Thanks in advance

bob

sushil8687 : On August 19, 2008 6:21 PM said:

I have a textbox where users are required to enter values starting with zero. The autocomplete does not match values read with leading zeros, is it a bug or do i have to do some settings.

deepesh : On August 21, 2008 9:23 AM said:

Just a small suggestion needed, if I change MinimumPrefixLength to 4 and then search for "New York",

then it does not count the space for it. ie "New " will not return any results.

Any suggestion for this?

Thanks

engineerachu : On August 22, 2008 1:55 AM said:

Nice work. But can you tell me, how to fetch values from Database? I mean using SqlConnetion and DataSet.

bahi44 : On August 26, 2008 11:01 PM said:

nice work but possible bog when using with firefox3, there's a gap between the textbox and the results, but there's no gap when using the same code in IE7, any idea anyone? and how can i show the results in someplace else, like a listbox?

anandjk1 : On August 28, 2008 5:08 PM said:

Hi

The video was helpful. I have tried to impliment the autocompleteExtender during the row editing of a gridview as shown below:

                           BackColor="White" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px"

                           OnRowEditing="Contact_Grdvw_RowEditing" OnRowUpdating="Contact_Grdvw_RowUpdating"

                           OnRowCancelingEdit="Milestone_Grdvw_RowCancelingEdit" CellPadding="3" AutoGenerateColumns="False">

                           

                           

                               <%--

                                   

                                       

                                           CausesValidation="false" />

                                   

                               --%>

                               

                               

                                   

                                       

                                           OnClientClick="return confirm('Are you sure you want to delete ?');" />

                                   

                               

                               

                                   

                                       

                                   

                                   

                                       

                                       

                                       ID="AutoCompleteExtender1"

                                       runat="server"

                                       TargetControlID="TextBox2"

                                       ServicePath="AutoComplete.asmx"

                                       ServiceMethod="GetCompleteList"

                                       MinimumPrefixLength="2"

                                       CompletionInterval="10"

                                       EnableCaching="true">

                                       </ajaxToolkit:AutoCompleteExtender>

                                   </EditItemTemplate>

                               </asp:TemplateField>

                               <asp:BoundField DataField="First_Name" HeaderText="First Name" />

                               <asp:BoundField DataField="Email" HeaderText="Email" />

                               <asp:BoundField DataField="Dept" HeaderText="Dept" />

                               <asp:BoundField DataField="Notify" HeaderText="Notify" />

                               <asp:BoundField DataField="Role" HeaderText="Role" />

                               <asp:BoundField DataField="contact_id" HeaderText="ID" />

                           </Columns>

                           <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />

                           <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />

                           <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />

                       </asp:GridView>

and the remaining webservice code and the services tag in the script manager tag are same as in your example.

When i use the above griview there are no errors but the auto complete feature doesn't work during the row editing.

Please help me out if i am missing some thing

Thanks

Anand

madhuri.d : On September 02, 2008 3:12 AM said:

Hi, Can anybody explain me how to get the sugessted values in a list using autocomplete extender with only the horizontal scrolling visible as the list is too large and goes very lengthy.I have tried iimplementing it with a <div id="div1" style="height:inherit; overflow:scroll">tag but it is showing both the vertical and horizontal scroll bars.

And also can I get the style sheet  explainig the other properties that are shown when a list is complete and item highlighted etc.

suresh2mail : On September 18, 2008 8:42 AM said:

Hi I have a two list boxes below this autocomplete extender, this is working fine in IE7 but in IE6  auto complete extender is going back to that two list boxes can any one suggest me how to resolve this issue

bthumber : On September 18, 2008 4:43 PM said:

Hi Joe

Do you have any sample in C# code like one below?

salma11 : On September 22, 2008 7:14 AM said:

Hello, you are great man, Thanks for your help

for c# code try this I did it and it is work well

using System;

using System.Collections.Generic;

using System.Web.Services;

using System.Data;

using System.Data.SqlClient;

using System.Web.Script.Services;

[WebService(Namespace = "http://tempuri.org/")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

[System.Web.Script.Services.ScriptService]

public class AutoComplete : WebService

{

   public AutoComplete()

   {

   }

   [WebMethod]

   public string[] GetCompletionList(string prefixText)

   {

       {

           string sql = "select Location_Name From Locations Where Location_Name like @prefixText";

           SqlDataAdapter da = new SqlDataAdapter(sql, "Server=(local);Database=altahaduth;uid=altahaduth;pwd=alta haduth123;");

           da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText + "%";

           DataTable dt = new DataTable();

           da.Fill(dt);

       //    List items = new List();

           string[] items = new string[dt.Rows.Count];

                      int i = 0;

           foreach (DataRow dr in dt.Rows)

           {

               items.SetValue(dr["Location_Name"].ToString(), i);

               //items.Add(dr["Location_Name"].ToString());

               i++;

           }

          // return items.ToArray();

           return items;

       }

   }

}

and in Html use this

                           

                               TargetControlID="txtloaction" ServicePath="AutoComplete.asmx"

               ServiceMethod="GetCompletionList"

               MinimumPrefixLength="1"

               CompletionInterval="500"

               EnableCaching="true"

               CompletionSetCount="12">

                           </cc1:AutoCompleteExtender>

I used .Net 2008

rvka123 : On September 22, 2008 9:13 AM said:

any one help me

i use ajax:autocompleteextender.

i got erroe on design mode

UNLNOWN Servertag ajax:autocompleteextender.

bendjoe : On October 05, 2008 10:36 PM said:

Hi,

Suppose I am getting a record from a table. This will give me a matching name in the table.How can I get the ID of the matching record?

Hope you under stood my question.

Thanks

jccastillo : On October 16, 2008 4:25 PM said:

Hi Joe, maybe you have a sample about this control using a database please ? was grate

ScriptStudios : On October 27, 2008 12:28 PM said:

Followed the vid.

Nothing happened.

Joy.

ScriptStudios : On October 27, 2008 2:49 PM said:

Aggravating.

I guess the AutoCompleteExtender is not calling the service.  When I test the service, it works as intended.

Hook up an AutoCompleteExtender and all bets are off.

Another disappointment.

carenski : On October 28, 2008 11:17 AM said:

Thanks Joe. This is very helpful and worked perfect. After putting it into my code, I slowly replaced the output using database.

The only changes I made to connect to a db is the web service file. Taken all the lines and replaced with the code below:

       Dim items As New List(Of String)

       ' ''build the list here based from DB.

       Dim objList As New cls_MgrNameComponent  ''BLL class

       Dim ds As New DataTable

       ds = objList.GetMgrList(prefixText, count)

       For Each dsRow As DataRow In ds.Rows

           items.Add(dsRow("userName").ToString + " [" + dsRow("PersonID").ToString + "]")

       Next

       Return items.ToArray()

Very very useful video. I'm ajaxified!

dabeDablin : On November 03, 2008 9:25 PM said:

Hi Joe How do you do this with databases

tennet : On December 02, 2008 4:28 PM said:

Dear Joe,

In the GetCompletionList function:

Public Function GetCompletionList( ByVal prefixText As String, ByVal count As Integer) As String()

How do you know to set two parameters and how did you know where to pass the values?

Scorpiogenie : On December 05, 2008 4:14 PM said:

Hello this is my WebService C# code.

using System;

using System.Data;

using System.Data.SqlTypes;

using System.Data.SqlClient;

using System.Drawing;

using Microsoft.SqlServer.Server;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Collections;

using System.Web.Services;

using System.Web.Services.Protocols;

using System.Web.Script.Services;

// Summary description for WebService

[ScriptService]

[WebService(Namespace = "microsoft.com/.../")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

public class WebService : System.Web.Services.WebService

{

   public WebService()

   {

       //Uncomment the following line if using designed components

       //InitializeComponent();

   }

   [WebMethod]

   public string[] GetProducts(string prefixText, int count)

   {

       string sql = "Select DISTINCT PERSON_ID, NAME from Person Where NAME like @prefixText";

       SqlDataAdapter da = new SqlDataAdapter(sql, "Data Source=.\\sqlexpress;Initial Catalog=FreedmansData;Integrated Security=True");

       da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText + "%";

       DataTable dt = new DataTable();

       da.Fill(dt);

       string[] items = new string[dt.Rows.Count];

       int i = 0;

       foreach (DataRow dr in dt.Rows)

       {

           items.SetValue(dr["NAME"].ToString(), i);

           i++;

       }

       return items;

   }

}

When I set the CompletionSetCount property of the autocomplete extender to 12, it returns all the query results instead of the number I assigned to the property. Help Please?

ruo : On December 10, 2008 8:07 PM said:

peace on u

i try code of salma11 on c#2005 but not work

plase i hope help

thank u

tony100 : On December 12, 2008 2:12 PM said:

i did try both joes code and database code nothing is happening . using VS 2008 sp1 and latest tool kit

am i missing something

tony

codeweaver : On December 27, 2008 4:43 PM said:

I like this guy's tutorials, however I agree with some of the other posters about the lack of depth. 90% of the people watching this will want to pull the data from a database, so lets include these steps in the videos, come on people!

Still, awesome video and I like how each video builds on the last one. By the way, make sure you include the following code (C#) or the webservice won't be picked up by the BLOCKED SCRIPT

[System.Web.Script.Services.ScriptService]

cjimerson : On January 06, 2009 10:26 AM said:

Will it be possible for someone or the code writer to show the example code of the example on the main page with the scrollbar.  I see a lot of forums where people can't get the scrollbar with the autocomplete function.

samuel24 : On January 15, 2009 6:13 AM said:

hi can any one say how to use two textbox with two different values using autocomplete

djibril_chimere_DIAW : On January 23, 2009 8:48 AM said:

Thanks ! Jërëjëf!

satyarups : On January 30, 2009 9:39 AM said:

Hi,

I am very new to AJAX.I am using the .net framework 2 and Visual Studio 2005. I installed the toolbox for .net framework 2. I am not creating an Ajax enabled page, but changing in existing c#.net page.

I tried to use the above example , initially I got the sys error. but later after going through various forums,  I changed some parts of web.config and I am not getting the error anymore.

However I am not getting the output...nothing happens when I type in characters. Is it the service is not getting called? how do I check?

I tried both the database example as well as the initial example.

I am getting a warning for the requirePermission (requirePermission="false")  in web.config. Is it the root cause?

Please help.

Regards,

Satya

Robie : On February 18, 2009 10:16 PM said:

I'm currently using version 1.0.20229 (VS 2005 version) and I was wondering if the latest version which is 3.0.20820 for VS 2008 a property to get the selected value when using it in key/value mode?

goodideadave : On February 19, 2009 7:53 PM said:

I added another method to the web service, like so:

[WebMethod]

   public string[] GetPayeeList(string prefixText)

   {

       string[] Items = GetData(prefixText, "payee");

       return Items;

   }

   [WebMethod]

   public string[] GetMemoList(string prefixText)

   {

       string[] Items = GetData(prefixText, "memo");

       return Items;

   }

GetData() gets the data from a stored procedure.

I then added another autocomplete extender, like so:

<table>

           <tr>

           <td>

           <asp:TextBox runat="server" ID="myTextBox" Width="300" autocomplete="off" />

           <ajaxToolkit:AutoCompleteExtender

               runat="server"

               ID="autoComplete1"

               TargetControlID="myTextBox"

               ServicePath="AutoComplete.asmx"

               ServiceMethod="GetPayeeList"

               MinimumPrefixLength="2"

               CompletionInterval="500"

               EnableCaching="true"

               CompletionSetCount="12" />

   </td>

   <td>            

           <asp:TextBox runat="server" ID="TextBox1" Width="300" autocomplete="off" />

           <ajaxToolkit:AutoCompleteExtender

               runat="server"

               ID="AutoCompleteExtender1"

               TargetControlID="myTextBox"

               ServicePath="AutoComplete.asmx"

               ServiceMethod="GetMemoList"

               MinimumPrefixLength="2"

               CompletionInterval="500"

               EnableCaching="true"

               CompletionSetCount="12" />

               </td>

       </tr>

   </table>          

When I enter something in the first autocomplete, it executes GetPayeeList and I get a list of values.  But when I choose a value it immediately executes GetMemoList, and does not show a list for the second autocomplete.  Any ideas what's going on?

rajasp : On March 15, 2009 3:49 AM said:

This is a really helpful article for an AJAX beginner like me. Thanks a lot, Joe.

I would like to know, should I always need to create a web service to achive this functinality. Can't I use any method on the page in which the control is present? If I can, Could you please explain how to do that?

Thanks!

PureDevelopers : On March 18, 2009 5:18 PM said:

The example posted at: http://www.asp.net/AJAX/AjaxControlToolkit/Samples/AutoComplete/AutoComplete.aspx

has some really cool css features, but you did not provide source code. If you could that would be great. there was some properties listed, but not a complete code sample.

i_jeylani : On March 19, 2009 1:56 PM said:

hi there,

i am having problems implementing the autocomplete using inforamtion picked up fomr a databse. wen i use the code exaample given above it works, but when i try pick up suggestions form a database it doesnt work :(

the source code is shown below

aspx file

DelimiterCharacters="" Enabled="True" ServiceMethod="GetCompletionLists" ServicePath="AutoCompleteSearchBox.asmx"

TargetControlID="AutoCompSearch" UseContextKey="True" CompletionSetCount="12"

MinimumPrefixLength="1" CompletionInterval="500">

asmx.vd

Imports System.Web

Imports System.Web.Services

Imports System.Web.Services.Protocols

Imports System.Data

Imports System.Data.SqlClient

Imports System.Collections.Generic

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.

" target="_blank">http://tempuri.org/")> _

<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _

<System.Web.Script.Services.ScriptService()> _

Public Class AutoCompleteSearchBox

Inherits System.Web.Services.WebService

Dim objTools As New Tools

<WebMethod()> _

Public Function GetCompletionList(ByVal prefixText As String, ByVal count As Integer) As String()

Dim SearchString As String

If (count = 0) Then

count = 10

End If

Dim params() As SqlParameter = New SqlParameter(0) {}

params(0) = New SqlParameter("@PrefixText", prefixText)

Dim EmployerList As DataSet = DALayer.SqlHelper.ExecuteDataset(objTools.getConn(), CommandType.StoredProcedure, "dbo.AutoCompleteSearchEmployer", params)

Dim items As New List(Of String)

For i As Integer = 0 To EmployerList.Tables(0).Rows.Count

SearchString = CStr(EmployerList.Tables(0).Rows(i).Item("EmpName"))

items.Add(prefixText + SearchString)

Next i

Return items.ToArray()

End Function

End Class

can anyone help... im not really sure wut is wrong, the DAlayer retruns rows according to the prefixtext, but it doesnt show in the interface as suggestions :s

i_jeylani : On March 19, 2009 2:40 PM said:

managed to fix it ;)

thanks for the post

sajithms85 : On April 02, 2009 5:40 AM said:

Try this code for accessing data from sql datbase for using it with the autocompleteextender

<WebMethod()> _

Public Function GetCompletionList(ByVal prefixText As String) as String()

Dim con As SqlConnection

con = New SqlConnection(ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString)

Dim dr As SqlDataReader

Dim cmd As SqlCommand

cmd = New SqlCommand("SELECT [ProductName] FROM [Alphabetical list of products] WHERE ProductName Like '" & prefixText & "%' ", con)

con.Open()

dr = cmd.ExecuteReader()

'dr = New SqlDataReader()

'Dim adp As New System.Data.OleDb.OleDbDataAdapter("select * from cars WHERE RecMerk Like '" & prefixText & "%' ", strConn)

Dim items As New List(Of String)

While (dr.Read())

items.Add(dr("ProductName"))

End While

con.Close()

Return items.ToArray

End Function

----------------------------------------------------------------------

<asp:TextBox runat="server" ID="myTextBox" Width="300" autocomplete="off" />

<ajaxToolkit:AutoCompleteExtender

runat="server"

ID="autoComplete1"

TargetControlID="myTextBox"

ServicePath="AutoComplete.asmx"

ServiceMethod="GetCompletionList"

MinimumPrefixLength="1"

CompletionInterval="500"

EnableCaching="true"

CompletionSetCount="12" />

------------------------------------------------------------------------

morojela : On April 20, 2009 9:36 PM said:

Hi

Wot If I need to pass several parameters to a web services, not only the "prefixText"

how can I do that?

Thanks

lili009 : On April 22, 2009 3:51 PM said:

This is great tutorial. Thanks Joe

Is it possible to allow multiple selections?

For example, the user types “L” the program recommends “Lisa”, “Linda”, “Luis” and the user selects “Lisa”

The user types a comma as a separator then continue to type “S”, the program recommends “Sam”, “Smith”, “Sara”, then the user selects “Sara”.

Now the user has selected two names: Lisa and Sara.

Thank you in advance

lili009 : On April 24, 2009 9:55 PM said:

I have fund that it is posible to have multiple selections by set up DelimiterCharacters

lili009 : On April 24, 2009 9:57 PM said:

I need to call an external web service, how can I pass Credentials?

Thank you in advance

jaikanthan : On April 28, 2009 5:38 PM said:

Hi sudheshna,

I am also receiving the same js error "Syntax error" as you faced. If you have any solution please help. I created a AJAXenabled web project only and have a master page.

I appriciate if anyone can help also

Thanks for your help in advance.

lili009 : On May 05, 2009 9:38 PM said:

Does anybody know how to develop a web parts by using the AutoComplete extender control? It does work on my aspx page, but did not figure out how to use it on SharePoint yet.

lili009 : On May 09, 2009 4:33 AM said:

It is working now. I use a user control on web parts

paracel_spratly_belongs_VietNam_hoangsaorg : On May 10, 2009 8:16 AM said:

Thank you in advance

that's realy so good!

danishjee : On May 10, 2009 8:24 AM said:

Great feature,

But I want to embaded database image(retrive from sql database) with autocomplete textbox with multi fields.(select user_name,user_address,user_image from tbUser).

kistanbullu : On May 13, 2009 1:27 PM said:

Hello I am able to use the autocomplete extender but I need to send an information from the web application into the web service, except than the to-be-completed word. How can I do that?

cbragdon : On May 26, 2009 2:28 AM said:

Hello, how do I use the autocomplete extender with SQL Server 2005 Endpoint - Web Service? None of the above examples deal with SQL Server 2005 Endpoints.

Thanks in advance

santaclaus1989 : On May 31, 2009 1:56 PM said:

too good as usual

mr.kiyak : On June 02, 2009 9:25 AM said:

Hi

How can we use this sample like facebook message box. I want to list my friends only. So I need to use Request.QueryString["MemberID"] or string MemberID = Session["MemberID"] and I can list the Member's friend on textbox field but we couldn't get value from querystring while use HttpContext.Current.Request.QueryString["MemberID"] and it's a depressing problem :)

bunny28 : On June 17, 2009 9:14 AM said:

first of all thanks jeo

its great,keep it up

hkieu : On June 17, 2009 2:23 PM said:

Hello Joe, I'm using the AutoCompleteExtender which shows up all countries and it works perfectly. But I have a second AutoCompleteExtender, it will show the city of the selected country. How to set up the ContextKey in Javascript to have the HiddenCountryID for my second AutoCompleteExtender? I just don't want the AutoPostback. Do you have any idea?

Thank you.

Cagmac : On June 25, 2009 11:07 AM said:

For people who want to get data from an external WebService have to consider the following 3 steps in your WebService proyect:

1. You have to add a reference of the ajaxControlKit.dll

2. Modify the webconfig, add the following:

<httpHandlers>

<remove verb="*" path="*.asmx"/>

<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

</httpHandlers>

3. include the following in your WebMethods:

[System.Web.Script.Services.ScriptService]

In adition I created the following webMethod to retrieve the servicePath, and consider it in the LoadEvent of my WebSite where the autocomplete extender is, because not always the web service runs in the same port:

[WebMethod]

public string GetMapPath()

{

return HttpContext.Current.Request.Url.OriginalString;

}

jafermt : On July 16, 2009 4:48 PM said:

how can i make a download link in my asp.net project to leav a chance for my visitors to download the data in pdf format,

please help me in this position

babji.sunny@gmail.com : On July 18, 2009 8:05 AM said:

Can any one let me know "How to use the auto suggest textbox based on a value selected in the Drop Down List". I mean to say in a page I will be having a Drop Down List and an AutoSuggestTextbox. The AutoSuggestTextbox should display the values based on the selection made in the DropDownList. Can any one let me know "How to achieve this"?

dilipnikam : On September 05, 2009 3:13 PM said:

Its Nice Control....I used in My project....

But i have one more requirement where i want Used this textbox for dataentry purpose.

For eg...

I will chose option from the autocomplete list or i will enter new text which i want to strore into my Database.

liad livnat : On September 17, 2009 12:05 PM said:

Problem to set focus to auto complete extender

haven't solved yet.

I have the following situation in my page: I've created a textbox and then set an AutoCompleteExtender to this textbox and, later I wanted to set the focus to this field with the code behind i set textbox.focus(), when i'm trying to add focus the AutoCompleteExtender simply not working, but when i click outside the text box and click back in , it's working.

Can anybody give me a simple explanation how to solve this situation, i dont want to do any workaround, is it a know issue (bug) ?

jigorokano : On September 24, 2009 9:27 PM said:

I have imported the source in visual studio 2008 bu non function. I have IE8 and then ajax tool kit release may 2009. I tested the web service and it is ok, bu when i try to type same char in the textbox don't open any windows. Have you a good idea?

thanks

deadea : On September 28, 2009 9:33 AM said:

gd

deadea : On September 28, 2009 9:42 AM said:

thx!

jmk.idnr : On October 06, 2009 7:30 PM said:

Ok, so would there be a way to use a couple of text boxes in the control?

I am thinking like if City State is entered into 2 text boxes can a list zipcodes be generated off of those city state combinations?

sharat80 : On November 14, 2009 6:52 PM said:

Thank you Joe Stagner,

This is very good tutorial for understanding the concept. We have a requirement to get list of suggessions in a textbox by retrieving data from oracle 10g database and can this be done without using web service and writing code in a page? Any ideas or approach will be very helpful to me.

Thanking you in advance,

Sharat

pMontu : On November 15, 2009 5:00 PM said:

same problem as @ScriptStudios, webservice is working + all steps followed but still autocomplete dosnt work ..

from the page:

Sys.Application.add_init(function() {

93 $create(AjaxControlToolkit.AutoCompleteBehavior, {"completionSetCount":12,"delimiterCharacters":"","id":"TextBox1_AutoCompleteExtender","minimumPrefixLength":1,"serviceMethod":"GetCompletionList","servicePath":"AutoComplete.asmx","useContextKey":true}, null, null, $get("TextBox1"));

somethings missing i guess

Leave a Comment

You must be logged in to leave a comment. Click here to log in.

Microsoft Communities