Ajax Dotnet AutoComplete Clear Cache

With the .net auto complete control, there is an attribute enablecache which tells the auto-complete to use caching or not. If this attribute is set to true, typing the same search text within a set number of seconds, instead of retrieving the data again from the database, the previous search results will be used.

Although caching is good in most cases, there are some cases where we need to clear the cache. For example, we have an auto-complete text-box, under this there are 2 check-boxes. Checking the check-box will change the search results. On clicking of the check-box we need to clear the cache of the auto-complete, so even though the same search text is enter, we need to do a complete new search again.

To do this, we can use the following java-script code on clicking of the check-box.

var autocompltebehaviour = $find(’autosearch’);
autocompletebehaviour._cache = null;

The id used in the $find function is the behaviour id attribute of the autocomplete textbox.
Using this method you can have both the caching of the autocomplete and no caching working at the same time.