Search code examples
jqueryasp.netautocompleteextender

Asp.Net Autocomplete set_contextKey "Object doesn't support this property or method"


I am facing a problem while setting the context key from the client side using jquery and javascript. It is unable to find the function set_contextKey of AutoCompleteExtender of ASP.Net.

Here is my HTML for textbox and AutoCompleteExtender...

<asp:TextBox ID="txtProduct" runat="server" AutoPostBack="true" OnTextChanged="txtProduct_TextChanged" Width="181px" /><ajaxToolkit:AutoCompleteExtender
    ID="AutoCompleteExtender_txtProduct" BehaviorID="acExt" runat="server" TargetControlID="txtProduct"
    CompletionListCssClass="autocomplete_completionListElement" CompletionListItemCssClass="autocomplete_listItem"
    CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem" MinimumPrefixLength="2"
    CompletionInterval="1000" ServicePath="~/WS/Service.svc" ServiceMethod="GetProductsByName"
    EnableCaching="true" DelimiterCharacters=";" UseContextKey="true" OnClientItemSelected="txtProduct_ClientItemSelected">
</ajaxToolkit:AutoCompleteExtender>

and the jquery on change of a dropdownlist is:

function ddlStore_onchange() {
    $('#acExt').set_contextKey($('#<%= ddlStore.ClientID %>').val());
}

It is throwing the error on set_contextKey function. Can anybody explain what I am doing wrong here...


Solution

  • I found out that replacing the line

    $('#acExt').set_contextKey($('#<%= ddlStore.ClientID %>').val());

    with this line

    $find('acExt').set_contextKey($('#<%= ddlStore.ClientID %>').val());

    resolved the issue. Don't know why exactly, can anybody help on this ?