48 votes
closed
AutoComplete - key value

Description

 
It would be nice if the autocomplete extender could return a key value pair,
example: UserId & UserName
as of now it only returns the UserName or UserId.


Closed Jul 10 2007 at 11:04 PM  by tedglaza
Closed with checkin 24539.

Comments

most recent at top (show oldest at top)
sakhamoori wrote Apr 15 2009 at 8:27 AM
How can i handle the height of the control when i get the data?

Somerled wrote Jul 16 2007 at 4:03 PM
Hi, I'm using the latest patch release - with the key value pair - in the text portion I'm putting a code (in square brackets) followed by the description of the code. In the Value portion I have an actual key value and some other data I need to stash into the client page when the user selects an item from the autocomplete dropdown. The problem I'm having is I need to replace the selected text with the code without the brackets and description - i.e. when the user selects an item, I want to cut up the text value and have the onClientSelected event put just the code value in the target control (textbox).

The strings I'm returning look like "[abc] This is the description of abc" - when they select the value I need just "abc" in the text box.

I have tried to use the set_text method of the eventArgs object which appears to work on the client side - i.e. you can see the new value when you alert - however the _setText function of the .js file still populates the text box with the value from the dropdown list

Can anyone tell me how to override this value?

Hope this makes sense

alinzju wrote Jul 11 2007 at 7:08 AM
Hi,
I use another way to achieve this feature - replace the _setText function:

function pageLoad() {
AjaxControlToolkit.AutoCompleteBehavior.prototype._setText = function(item) {
......
var text = (item && item.firstChild) ? item.firstChild.nodeValue.split(":")[0] : null;
......
}
}

Phanatic wrote Jul 9 2007 at 5:41 PM
Hi ,

Yet another AutoComplete Key-Value Patch From me :-)

This implementation is based on the suggestion of using a keyValueSeparator to concatenate the Keyand the Value on the server and splitting it on the Client using the Same keyValueSeparator String.

The Server-Side method returns an array of strings as it does currently and the only change to the Method Signature is addition of a new Parameter of type string called as keyValueSeparator .
The developer has to specify the keyValueSeparator on the ClientSide and the same is passed to the Server-Side Method using the keyValueSeparator parameter.
Example Method Signature :
[WebMethod]
public string[] GetCompletionList( string prefixText, int count, string keyValueSeparator)

In case you are using the DynamicContextKey , the signature would be :
[WebMethod]
public string[] GetCompletionList( string prefixText, int count, string contextKey,string keyValueSeparator)

Please let me know about any feedback / comments

alinzju wrote Jul 5 2007 at 3:13 AM
hi Phanatic,
thank you for your helps, but i can't change the value of textbox1:

<asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender runat="server" BehaviorID="AutoCompleteEx" .......
........TargetControlID="TextBox1">
</ajaxToolkit:AutoCompleteExtender>
........
<script>
function pageLoad() {
$find("AutoCompleteEx").add_itemSelected(setValue);
}
function setValue( source, eventArgs ) {
$find("AutoCompleteEx").get_element().value = eventArgs.get_text().split(":")[0];
}
</script>

after the setvaleu() function, the value of textbox1 resume to "key: value" immedialy!!!

Phanatic wrote Jul 4 2007 at 2:38 PM
Hi guys,

I appreciate the attention this patch has got .
I have modified the patch to fix the issue with FireFox .
As of now , I am evaluating other options of implementing the same functionality and this might change in the near future .
I hope you understand.

Thanks,
Phani Raj

avbers wrote Jul 3 2007 at 5:21 PM
Would be nice..
this is a MUCH requested feature, because double requests for this item exits
Maybe it is better to group these together to get an overview of the feature requests
(11 votes) http://www.codeplex.com/AtlasControlToolkit/WorkItem/View.aspx?WorkItemId=8553
(4 votes) http://www.codeplex.com/AtlasControlToolkit/WorkItem/View.aspx?WorkItemId=8859
(1 vote) http://www.codeplex.com/AtlasControlToolkit/WorkItem/View.aspx?WorkItemId=7528

strange this is why some of them have been closed...

Phanatic wrote Jun 28 2007 at 5:20 PM
Hi all,
I have also updated the instructions to use the tool on my blog :
http://blogs.msdn.com/phaniraj/archive/2007/06/19/how-to-use-a-key-value-pair-in-your-autocompleteextender.aspx

Thanks,
Phani Raj

Phanatic wrote Jun 28 2007 at 5:07 PM
Hi All,
As requested by Somerled , I haved added a new property called as OnClientItemSelected on the ACE which hooks up the Cilent Side event handler for the ItemSelected Event .
You no longer need to add the handler yourself by using the add_itemSelected Event , just specify the function as the value of the OnClientItemSelected property in the markup for the ACE.
Keep the Feedback coming....

Somerled wrote Jun 28 2007 at 11:46 AM
It would be even handier if the event you are adding to process the selection could be defined in the controls definition i.e. something like onItemSelect="ProcessMe"

tonb wrote Jun 26 2007 at 11:14 AM
This looks like exactly what I need. One more question though: wouldn't you want to fire an event to the server when an item is selected? What I need is to respond at server side to a user selecting an item, using the selected item VALUE. I'm totally not into javascript, so, is this difficult to add?

jsiegmund wrote Jun 26 2007 at 8:01 AM
I used the patch mentioned and got exactly the result I was looking for. By adding some little client side javascript I was able to store the key value in a hidden field which is bound to my datasource: works perfectly! Therefore I think this patch should be in the next release.

Phanatic wrote Jun 22 2007 at 3:06 PM
Hi Alinzju ,
You can do that with the existing autoCompleteExtender by
1) Return key:value from the server
2) Handle the itemSelected Event by adding an event handler
add_itemSelected( getValue );
function getValue( sender,eventArgs) {
alert( eventArgs.get_text().split(":")[0]+"is Key and value is :"+eventArgs.get_text().split(":")[1] );
}
so ,
if you return "Key : Value 1 " from the Server
get_text() will return "Key:Value 1"
get_text().split(":") will give you a string array of size 2 and the first element would be the Key and the second would be the value
Hope this Helps

alinzju wrote Jun 22 2007 at 4:07 AM
but it can not show value in the list, like:
key1: value1
key2: value2
key3: value3
.......
when you select key1: value1, it only fill "key1" in the textbox.

Phanatic wrote Jun 19 2007 at 3:51 PM
I blogged about how to use the Patch Here -->
http://blogs.msdn.com/phaniraj/archive/2007/06/19/how-to-use-a-key-value-pair-in-your-autocompleteextender.aspx
Hope this helps.

Thanks,
Phani Raj

Phanatic wrote Jun 19 2007 at 2:27 PM
Hi ,
Please Ignore the previous Patch .
I changed the behavior to remove the KeyValueSeparator and instead process a custom type ( AutoCompleteKeyValuePair) from the Server-Side method .
The way one would use it is to set the UseKeyValueMode property on the ACE to "true" and return an array of AutoCompleteKeyValuePair[] from the server-side Method.
You can access the Value of the Selected Item by subscribing to the itemSelected Event by using the add_itemSelected method on the ACE behavior .
EX: in the markup , you write :
<ajaxToolkit:AutoCompleteExtender runat="server" BehaviorID="AutoCompleteEx" .......
........UseKeyValueMode="true">
</ajaxToolkit:AutoCompleteExtender>

You hook-up the event Handler for the itemSelected Event by running :

$find('AutoCompleteEx').add_itemSelected(IAmSelected);

The Server-Side Method looks like this :
public AutoCompleteKeyValuePair[] GetCompletionList(string prefixText, int count) {
...................
}

When an item is selected , the Event handler previously added using add_itemSelected() is called and you can access the value .
ex:
function IAmSelected( source, eventArgs ) {
alert( " Key : "+ eventArgs.get_text() +" Value : "+eventArgs.get_value());
}
I have updated the Documentation , tests , to reflect this .

Thanks,
Phani Raj

Phanatic wrote Jun 18 2007 at 9:55 PM
Hi all,

I wrote a fix for this which allows one to return Key-Value Pairs from the Server-Side and use them on the Client Side.
The Kay-Value will be part of the same string which will be concatenated with a special character that you decide to use as the separator.

I added 2 properties called as UseKeyValueMode( Boolean ) and KeyValueSeparator ( String ).
Server-Side WebMethod/Page Method concatenates the Key and the Value using the KeyValueSeparator and the client-side javascript processes the results accordingly .
ex: KeyValueSeparator ="ACESeparator"
If Server returns the Key-Value pair as : PhaniACESeparatorRaj
Then Key is Phani , Value is Raj.
You can return your data in the format of :
CustomerName<KeySeparator>CustomerID
In your autocompleteextender set the above 2 properties appropriately and you should be good to go .
I Hope this will be a very useful addition to the already awesome toolkit !
Thanks,
Phani Raj

pdeviggi wrote Jun 11 2007 at 7:16 PM
I agree!!! This nice control is useless for our dev group, for 2 reasons:
1. The lack of key value, asi this item says
2. The textbox TextChanged event seems to be filtered, and it is very important

We use instead a Combo.ascx that combines a TextBox + a DropDownList, you can see it at codeplex.com/netopenfwk and also at the attached picture (see just below the "Impagos de Cliente" label)

Good luck!
Pedro

sauser wrote May 22 2007 at 12:10 AM
sounds good!

muk wrote May 21 2007 at 11:06 PM
ditto. retrieving a key/value pair is crucial. unfortunately, this otherwise nifty control is basically useless to me.

alinzju wrote May 12 2007 at 7:24 AM
yes, i need it too!

fredfabel wrote May 3 2007 at 5:44 PM
this is essential when autocomplete represents a data base item

Updating...
© 2006-2010 Microsoft | About CodePlex | Privacy Statement | Terms of Use | Code of Conduct | Advertise With Us | Version 2010.1.12.16187