Reputation: 1127
I don't want to use a webservice to populate an autocomplete extender on a textbox. In this case, it's where the user is entering country name and I don't want to make a trip to the database every single time. I'd much rather keep a collection in session state and 'bind' the autocomplete to that.
Is it possible to set ServicePath and/or ServiceMethod to something in the codebehind as opposed to a webservice?
Regards kumar
Upvotes: 3
Views: 2887
Reputation: 1932
you can set the onclientpopulating attribute to your local javascript function something like onclientpopulating="onPopulating" and then in that js function provide the local data instead of hitting the web service. below is one of the implementations which i used which never hits the webservice. completionData variable holds all the data through which i iterate to find the match based on what the user entered in the text box. This is an old example. i probably would do it little differently if i implemented it now.
function onPopulating(ace, args)
{
var prefixText = ace._currentCompletionWord();
var filteredItems = GetFilteredItems(prefixText);
ace._update(prefixText,filteredItems,false);
args.set_cancel(true);
}
function GetFilteredItems(prefixText)
{
var filteredItems = [];
for (var nCount=0; nCount < completionData.length; nCount ++)
{
if (completionData[nCount].startsWith(prefixText))
{
Array.add(filteredItems,completionData[nCount]);
}
}
return filteredItems;
}
Upvotes: 0
Reputation: 33476
Unfortunately, there is no direct option to do that other than hacking into javascript to stop the browser from making a call to get the list.
The only other choice I can see is to create a webservice & use EnableCaching
property of AutoCompleteExtender
, to make sure the result of the webservice is cached on the client, thereby avoiding calls to webservice (and database in turn).
EDIT: On a second thought, I think it could be possible to mark a public static method in your page with WebMethod
attribute & set the ServicePath
to your aspx page.
see if this helps - http://blogs.msdn.com/sburke/archive/2006/10/21/hint-components-that-use-web-services-with-asp-net-ajax-v1-0-beta.aspx
I think it should work. But am not sure, if the framework requires it to be the webservice.
Upvotes: 1
Reputation: 4931
You can use a local asmx file inside your existing web project and connect to that. There you can put any logic you require here so you don't have to hit a database if you don't want to. It's really just like another webpage that should have no problems accessing session state.
Upvotes: 0
Reputation: 12975
Does your list of countries change, or vary by user? It doesn't seem to make sense to put this in session state, either. I don't see why you should hit the server for this.
Consider rendering all of your values directly into HTML and then using Javascript to autocomplete entirely on the client side.
Upvotes: 0