15.2. Automatically Completing Data As the User Types

The AutoCompleteExtender enhances the ASP.NET TextBox control. As the user types characters, the extender monitors the input and tries to match words or data provided by a Web service. (For details on working with Web services, see Chapter 9.)

In this section, you create a text box that helps users tag a blog post. For blog readers, the tags are often displayed in a cloud where the size and font of the tags indicate the most popular subjects.

15.2.1. Preparing the word list

The Web service reads from a list of words that you create as a text file. (You could get the words from a database or XML file, but a flat text file is less complicated.) Follow these steps to create the list of tag words:

  1. Add a text file named cloudtags.txt to your App_Data folder (select App_Data; then choose FileNew FileText FileAdd).

  2. In cloudtags.txt, add the tags, one name per line followed by a carriage return.

    Using the following example tags (from my ASP.NET blog at http://weblogs.asp.net/kencox/) will make it easier to follow along later. At a minimum, enter the names that start with V:

ASP.NETVista
Visual Studio.NET
AJAXAtlas
C#Community News
DataContext ...

Get ASP.NET 3.5 For Dummies® now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.