SIGN UP MEMBER LOGIN:    
ARTICLE

Creating auto-complete TextBox using AutoCompleteExtender Control of AJAX

Posted by Ankit Nandekar Articles | AJAX in C# February 24, 2011
This article demonstrats how to create an auto-complete TextBox in ASP.Net using Ajax’s AutoCompleteExtender.
Reader Level:
Download Files:
 

This article demonstrats how to create an auto-complete TextBox in ASP.Net using Ajax's AutoCompleteExtender.

Note: We are assuming that you have already completed the installion of the Ajax Toolkit as well as have a basic understanding of coding.

This article provides a few steps which will be easy to follow.

Step 1:

Before you can use any of the Ajax Control Toolkit controls in a page, you first need to add a ScriptManager to the page. You can drag the ScriptManager from the Visual Studio Toolbox window onto the page. The ScriptManager is located in the Ajax Control Toolkit tab under the Toolbox.

Step 2:

Add a TextBox Control to the page.

Step 3:

Add an AutoCompleteExtender; you can drag the AutoCompleteExtender from the ajax control toolkit.

        <cc1:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server"
            DelimiterCharacters="" Enabled="True" ServiceMethod="GetCompletionList"
            ServicePath="" TargetControlID="TextBox1" UseContextKey="True">
        </cc1:AutoCompleteExtender>

Step 4:

Add a Service method in code. Expanding the textbox control smart tag, select the add AutoComplete page method option from the provided menu. This action creates a service method in code behind for your page; it looks like this:

[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] GetCompletionList(string prefixText, int count, string contextKey) {
return default(string[]);
}

Step 5:

Write the following code in the service method.

[System.Web.Services.WebMethodAttribute(),System.Web.Script.Services.ScriptMethodAttribute()]
 public static string[] GetCompletionList(string prefixText, int count,string contextKey)
    {
 string[] country = { "America", "italy", "india", "Russia", "england", "japan" };
        return (from m in country where m.StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase) select m).Take(count).ToArray();

}

Run your website...............

Login to add your contents and source code to this article
share this article :
post comment
 

good and simple example .. With database interaction, article... http://www.c-sharpcorner.com/UploadFile/suthish_nair/3997/

Posted by Suthish Nair Feb 25, 2011

thnx for ur valuable comment...

Posted by Ankit Nandekar Feb 25, 2011

Nice post! That's all i need to learn.

Posted by Kayleigh Feb 24, 2011

Greate Article thank u.....

Posted by Kiran Karale Feb 24, 2011
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Team Foundation Server Hosting
Become a Sponsor