---
title: "ASP.NET Jquery Autocomplete"  
description: "ASP.NET Jquery Autocomplete"  
author: "Jayden Bell"  
published: 2014-08-25  
updated: 2014-08-25  
canonical: https://www.mindstick.com/forum/2129/asp-dot-net-jquery-autocomplete  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 1 minute  

---

# ASP.NET Jquery Autocomplete

I have an [ASP.NET webforms](https://www.mindstick.com/forum/155702/difference-between-asp-dot-net-webforms-and-asp-dot-net-mvc) [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) and trying to implement jQuery autocomplate on a text box. The server code is getting called, but nothing is displayed. I've replaced the call to the [web service](https://www.mindstick.com/articles/895/web-service-introduction) and added some [static](https://www.mindstick.com/articles/12098/the-static-keyword-the-static-methods) text and that gets displayed OK. Can [anyone](https://www.mindstick.com/articles/23207/how-to-find-the-best-fit-job-for-anyone) see what the issue is?

**The [server side](https://www.mindstick.com/forum/318/how-to-call-javascript-fuction-in-server-side) code is here:**

```
[WebMethod]    public string[] ReturnPostcodes(string term)    {        PostcodeService postcodes = new PostcodeService();        var results = postcodes.ReturnPostcodes().Where(p => p.Postcode.StartsWith(term.ToUpper())).Select(p => p.Postcode).Take(20).ToArray();        return results;    }The HTML is here:<tr>        <td>Mobile Telephone:</td>        <td><asp:TextBox runat="server" ID="txtPostcode"></asp:TextBox></td>    </tr>The jquery is here:$(document).ready(function () {        $('#ctl00_ctl00_mainContent_mainContent_txtPostcode').each(function () {            $(this).autocomplete({                 source: '/Postcodes.asmx/ReturnPostcodes'            });        });    });
```

## Replies

### Reply by Sumit Kesarwani

Hi jayden, try this:

```
<script type="text/javascript">        $(function ()
{            var lastXhr, cache = {};            $('#<%=Search.ClientID %>').autocomplete({               
source: function (request, response) {                   
var term = request.term;                    if(term in cache) {                       
               response(cache[term]);                       
            return;                    }                   
lastXhr = $.ajax({                       
type: "POST",                      
 url:"Default.aspx/GetBooks",                       
data: "{ \"term\": \"" + request.term +"\" }",                       
contentType: "application/json; charset=utf-8",                       
dataType: "json",                       
success: function (data, status, xhr) {                           
cache[term] = data.d;                           
if (xhr === lastXhr) {                               
response(data.d);                           
}                       
}                   
});                }            });        });    </script>
```


---

Original Source: https://www.mindstick.com/forum/2129/asp-dot-net-jquery-autocomplete

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
