So far it has been a royal pain. The supposed documentation link mentioned above...
http://blogs.msdn.com/phaniraj/archive/2007/06/19/how-to-use-a-key-value-pair-in-your-autocompleteextender.aspx?CommentPosted=true#commentmessage
either is so old that it doesn't work or they are nuts.
I have a web page that has several options that a user might want and I use multi-views to deliver these. In one of the views I have four checkboxes for the user to choose among. I have four autocomplete instances to complement the four checkboxes. My calls to the database and my loading the autocomplete with a key/value pair is now working fine (after a couple day searching and trying a bunch of crap).
Reading the "documentation" I have to write some javascript to intercept the selection. Then to hook it up I am to define the OnClientItemSelected property with the function name I made in the javascript. Sounds simple - doesn't work, but still simple.
Next I am to some how (no documentation given) extract the key/value pair and trigger a server-side event. The "documentation" as shown will not cause an event to fire on the client. Then since the event never fires there is no chance of sending anything to the server (even if we knew how to do that.)
People like me have to search endlessly and read hundreds of blogs and posts trying to find clues to something that should be simply written down. I never have understood why someone doesn't put up a complete post. I do. Imagine the time that would be saved by the developers if they actually showed us how to use it the way they intended it to be used. But no, that is far too simple. No the "norm" is to write simple partial routines of snippet code that doesn't work to give the community a hint of what is supposed to be done. And then to repeat that flawed process over and over.
So is anyone up to the task? Can a working example actually be wrtten? Is there anyone out there who can actually demonstrate how to postback a value pair in a single aspx page with codebehind?
Larry Aultman
As I said the client side even does not fire as written. If you add the () to the declaration the event fires but naturally the signatures don't match so the call fails.
Here is what DOES NOT WORK to save you some time...
<
script language="javascript" type="text/jscript">
var textBoxcoName; //alias to the tbcoName textbox name
var hiddenTextValue; //alias to the hidden field: hideValue
var hiddenUserID; //alias to the hidden field: hideUserIDfunction pageLoad()
{
textBoxcoName = $get(
"<%=tbcoName.ClientID %>"); //gets the fully resolved name for the textbox control
}
function AutoCompleteExtender2_ItemSelected(source, eventArgs )
{
alert(" Key : "+ eventArgs.get_text() +" Value : "+eventArgs.get_value());hiddenTextValue = $get("<%=hideValue.ClientID %>");
hiddenTextValue.Value = eventArgs.get_text();
hiddenUserID = $get("<%=hideUserID.ClientID %>");
hiddenUserID.Value = eventArgs.get_value();
textBoxcoName.OnTextChanged;
}
</
script>
....some html page formatting ...
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" EnablePageMethods="true"></asp:ScriptManager>
<asp:HiddenField ID="hideValue" runat="server" /><asp:HiddenField ID="hideUserID" runat="server" />
... some more html page formatting ...
<asp:TextBox ID="tbcoName" runat="server" CssClass="txtBx"></asp:TextBox><cc1:AutoCompleteExtender ID="AutoCompleteExtender2" runat="server"
EnableCaching="true" CompletionSetCount="10"
CompletionListCssClass="autocomplete_completionListElement"
CompletionListItemCssClass="autocomplete_listItem"CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
MinimumPrefixLength="2" TargetControlID="tbcoName"
ServiceMethod="getCompanyNames" DelimiterCharacters=""
OnClientItemSelected="AutoCompleteExtender2_ItemSelected">
</cc1:AutoCompleteExtender>