views:

391

answers:

1

I have an auto complete extender on my web page that when typed in gets address info from a database. I need to make two calls to the database, one to get a list of brief descriptions of addresses and another to get all the address information once an address description is selected. To make the second call I get a unique ID from the first call (If this is making sense). So far I have an auto complete extender that as I type in address information pulls back the list of descriptions, which is fine, but I have no way to pass back the unique ID (Which I don't want to show to the user). Is there anyway to pass back the unique ID in the web service without the user seeing it?

A: 

I'm not totally sure what you mean or what your level is, so this might not be what you are looking for:

When doing your (ajax?) call to the server to get the list of descriptions, you'll probably get a plain list of normal strings representing the possible descriptions. Instead of using plain strings, use something like JSON, where you put both id and name in. You can then fill your list of autocompletes using something like

foreach(var obj in suggestions)
    addToList(obj.Name);

Have a collection with the original suggestions somewhere in memory (like the variable 'suggestions'); and when someone selects an autosuggested item, you can find the item back in your original array.

foreach(var obj in suggestions)
    if(obj.Name == document.getElementById('suggestionTextbox').value) return obj.id;

With the id, you can do a new call to the database using PageMethods or other kinds of Ajax stuff. When using PageMethods (Google for exact def.) use something like this:

public static object GiveExtraInfo(string id)
{ //look up data in database and return the required object }

You can then do in JavaScript

var content = PageMethods.GiveExtraInfo(/*the id you selected before */);

You can now use the content whereever you like in the page.

Jan Jongboom
Currently i'm using Microsofts built in AutoCompleteExtender control that comes with ASP.Net AJAX. I've thought about making my own javascrpt method (With JSON) the only problem is I've had errors with changing controls on the page and the viewstate.
Jack Mills
I for one use http://www.pengoworks.com/workshop/jquery/autocomplete.htm to do something like i've said in my comment. It's way more extensible.
Jan Jongboom