What is ID. If it is a variable then it won't work. You will have to store it somewhere. May some Hidden Field.
And then use the ID of HiddenField
function SetContextKey()
{
$find('<%=AutoCompleteExtender1.ClientID%>').set_contextKey($get("<%=HiddenField1.ClientID %>").value);
}