how to display USA "county" in dynamic textbox when user starts typing first letters etc

Matt Matt 0 Reputation points
2025-12-20T19:28:07.3733333+00:00

hi,

I am using asp.net web forms and C sharp.

There is a web form on the site. One of the textboxes is "USACounty" I want the full

county to show up in the textbox automatically when a users starts typing...... for instance they type san d and it gets populated with - SAN DIEGO.

Thank you for any examples.

M

Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Q&A Assist
    2025-12-20T19:29:21.1366667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To achieve dynamic population of the "USACounty" textbox in an ASP.NET Web Forms application, you can utilize the AutoCompleteExtender control from the ASP.NET AJAX Toolkit. This control allows you to call a web service that returns county names based on the user's input. Here’s a step-by-step guide:

    1. Add the AJAX Control Toolkit: Make sure you have the AJAX Control Toolkit referenced in your project. You can download it from GitHub.
    2. Configure your Web.config: Add the following line to your web.config file under the <controls> section to register the AJAX Control Toolkit:
         <add namespace="AjaxControlToolkit" assembly="AjaxControlToolkit" tagPrefix="ajaxToolkit"/>
      
    3. Create a Web Service: Create a web service that will return a list of counties based on the input. For example:
         [WebMethod]
         [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
         public string[] GetCounties(string prefix)
         {
             // Sample data; replace with actual data retrieval logic
             string[] counties = { "SAN DIEGO", "SAN BERNARDINO", "SANTA CLARA", "SANTA CRUZ" };
             return counties.Where(c => c.StartsWith(prefix.ToUpper())).ToArray();
         }
      
    4. Add the AutoCompleteExtender to your TextBox: In your ASPX page, add the TextBox and the AutoCompleteExtender control:
         <asp:TextBox ID="USACounty" runat="server"></asp:TextBox>
         <ajaxToolkit:AutoCompleteExtender
             ID="AutoCompleteExtender1"
             runat="server"
             TargetControlID="USACounty"
             ServiceMethod="GetCounties"
             MinimumPrefixLength="2"
             CompletionInterval="1000"
             EnableCaching="true"
             CompletionSetCount="10">
         </ajaxToolkit:AutoCompleteExtender>
      
    5. Test the Implementation: Run your application and start typing in the "USACounty" textbox. It should dynamically suggest county names based on the input.

    This setup will allow users to see suggestions for counties as they type, enhancing the user experience on your web form.


    References:


  2. Matt Matt 0 Reputation points
    2025-12-20T22:59:48.3666667+00:00

    is there a way I can do this without installing visual studio. I have entry level notebook without much space. I am using notepad at the moment to upload and

    work on my aspx files. for some reason I am getting error now after after downloading

    and transferring by ftp the files to the server. Do I need to upload all the files or just the AjaxControlToolkit folder that is within the master directory.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.