This tutorial was created with and aimed toward users of Visual Studio.NET 2008. 2005 can be used, but Microsoft’s ASP.NET AJAX Extensions, which can be downloaded at this location, must be installed.
Microsoft have a Control Toolkit that is not included with the .NET Framework, but can be downloaded from www.codeplex.com/AjaxControlToolkit. This Toolkit is constantly being updated and consists mainly of AJAX Extenders for existing ASP.NET Controls.
In this tutorial, you will learn how to implement something similar using the AutoComplete AJAX Control and a Web Method.
We can then create our Web Method like so:
Here we are creating a Web Method within the page. We could create this as a Web Service, but for this example we are only using it on this page.
We will also have a button that will move the chosen suggested text to a label:
Our entire code-behind will look something like this:
Now we have built our Web Method, we will implement it into our ASPX page. We will first add the following ASP.NET Controls: a TextBox, Button and Label. Also make sure there is a ScriptManager, and an UpdatePanel if you want the form to make use of Asynchronus Postbacks.
Now if we go into Design view of our ASPX page, we can click on the SmartTag of the TextBox and choose Add Extender. This will only be available if we have the AJAX Toolkit installed.
The AutoComplete Extender is also smart enough to provide caching – it will detect if the search term has been previously entered, and if so, it will not need to make another call to the database; it will retrieve results from cache.
Thanks for this tutorial, I’ve been trying to find a simple way to implement this over the past few weeks without any luck, until I found yours. Your method is simple and the attached sample is a big plus.
Cheers! Thanks a gain and keep up the good work for newbies like me.
Just a quick question, is there any performance issues using a large Database with thousands of records for the returned suggestions? my test DB contains 5,000 plus records with about 20 plus Data fields and the tests I’ve done on my PC with just me using the BD, I can’t see any performance issues. Do you know by any chance if this will cause major problem for multi-users app? Thanks in advance for any feedback
I could not get this to work. It returns the data from the data base but does not display it in the textbox. All the other stuff works. Whatever is typed in is displayed in the lblChosenName label
I could not get this to work. It returns the data from the database but it does not put it in the text box. Whatever was typed in the textbox is displayed in the label. the TargetControlID of the AutoCompleteExtender is the ID of the textbox.
|Heval Challi said:
Thanks for this tutorial. I have added 1 more column (phone)to the table which shows the phone #. Could you please let me know how to retrive the name and phone number together of a person?
Work like a treat.
Thanks for the tutorial. how would I convert this to a webservice?
What is the meaning of this code
Dim db As New NamesDataContext()
Return db.tblNames.Where(Function(n) n.name.StartsWith(prefixText)).OrderBy(Function(n) n.name).Select(Function(n) n.name).Take(count).ToArray()
In my case it is giving error NamesDataContext() not defined.
i would agree with tanuj, its giving me namesdatacontext not defined………
|Philip Keefer said:
THANKS! Works like a charm and is just what I needed.
i want this code in C# please post replay