Hay,
I have downloaded the latest AjaxControlKit changeset with number (at that time) 24719 and added a small bit of code, just to make life a little easier ;-). With this piece of code you just specify the ID of a hidden field that holds the key value.
AutoCompleteExtender.cs
1. Added property to the class AutoCompleteExtender:
[DefaultValue("")]
[ExtenderControlProperty]
[IDReferenceProperty(typeof(HiddenField))]
[ClientPropertyName("keyHiddenFieldID")]
public string KeyHiddenFieldID
{
get { return GetPropertyValue("KeyHiddenFieldID", ""); }
set { SetPropertyValue("KeyHiddenFieldID", value); }
}
AutoCompleteExtender.js
1. Added field to the class AjaxControlToolkit.AutoCompleteBehavior:
this._keyHiddenFieldID = null;
2. Added property to the class AjaxControlToolkit.AutoCompleteBehavior.prototype:
get_keyHiddenFieldID: function() {
/// <value type="String" maybeNull="true">
/// ID of the hidden field control that holds the key value of the selected key-pair item.
/// </value>
return this._keyHiddenFieldID;
},
set_keyHiddenFieldID: function(value) {
if (this._keyHiddenFieldID != value) {
this._keyHiddenFieldID = value;
this.raisePropertyChanged('keyHiddenFieldID');
}
},
3. Added code to the eventhandler onKeyDown where the tab is processed:
_onKeyDown: function(ev) {
...
else if (k === Sys.UI.Key.tab) {
if (this._selectIndex !== -1) {
this._setText(this._completionListElement.childNodes[this._selectIndex]);
}
if (this._useKeyValuePairs) {
var keyControl = $get(this._keyHiddenFieldID);
if (keyControl) {
keyControl.value == null;
}
}
}
...
},
4. Added code to the eventhandler setText:
_setText: function(item) {
...
if (this._useKeyValuePairs) {
var keyControl = $get(this._keyHiddenFieldID);
if (keyControl) {
keyControl.value = (item ? item._value : null);
}
this.raiseItemSelected(new AjaxControlToolkit.AutoCompleteItemEventArgs(item, text, item ? item._value : null));
} else {
this.raiseItemSelected(new AjaxControlToolkit.AutoCompleteItemEventArgs(item, text));
}
...
},
With kind regards,
Dennis
May the source be with you...