3

Normally, I can can set the TargetControlID server side using something like this:

    AutoCompleteExtender ace = new AutoCompleteExtender();
    ace.ID = "AutoCompleteExtender1";
    ace.TargetControlID = "whatever";

I know how to grab the AutoCompleteExtender client side, but I am looking for a method to update the TargetControlID client side too. Any ideas?

Techgration
  • 516
  • 4
  • 16
  • Maybe it's not even possible?? http://forums.asp.net/t/1242007.aspx/1 – Techgration May 20 '11 at 16:16
  • 2
    See if jQuery Autocomplete helps: http://jqueryui.com/demos/autocomplete/ – gbs May 20 '11 at 16:37
  • I like the suggestion for the future (jQuery autocomplete). I will probably switch over in the future. But I'm on a project deadline so I can't switch midstream :) – Techgration May 20 '11 at 16:45
  • 1
    Taking that TargetControlID cannot be changed, wondering about the scenario why you want to change it on client-side? – gbs May 20 '11 at 16:54
  • Good question. I thought it would be an easy way to load up all of the elements service methods, but now that I realize it isn't possible, I added a function server side to do it. – Techgration May 20 '11 at 23:49
  • The only way you can change TargetControlID is updatepanel wrap the control in update panel and make an async call to server that should do it. – Kamran Pervaiz Apr 19 '12 at 14:40
  • 2
    It's stuff like this that made me give up on the AJAX control toolkit. If you want to do anything even slightly out of the ordinary, you're gonna have a bad time. I swapped it out for just using JQuery and Page Methods and never looked back. – Karl Nicoll Apr 21 '12 at 00:19

2 Answers2

2

Well sadly this is not possible for existing instance of AutoCompleteExtender. There are a few methods that you might be interested in like below

var x = $find("AutocompleteBehaviorID");//find the instance

x.get_completionListElementID();//get the ID of target textbox

x.set_completionListElementID();//set the ID of target textbox has no effect though :(

x._completionListElement();//direct access to DOM element that acts as target

the problem here seems initialized version attaches additional events to target textbox during init phase of the control toolkit( yeah client side too has a init phase). When a initialized version is made to change as the target (as you wanted to do) then these events keypress,blur etc are not added hence you don't see any changes. But if you knew javascript you can do the below to make it work with any textbox.

$create(Behavior,{properties},{events},interfaces,target);

where

Behavior

AjaxControlToolkit.AutoCompleteBehavior

properties

is a javascript object as below (there are more properties but these suffice

{
    "completionInterval": 1,
    "completionListElementID": "empty panel id",
    "completionListItemCssClass": "css class name",
    "delimiterCharacters": ";",
    "highlightedItemCssClass": "css class name",
    "id": "CLIENTSIDEID",
    "minimumPrefixLength": 1,
    "serviceMethod": "WebMethodName",
    "servicePath": "AbsolutePath to asmx file"
}

Events

there are more events available

{
    "itemSelected": jsFn,
    "populated": jsFn
}

The Target

Target element is the most important. It is this text box that all the events ,bells and whistles attracted to.

$get("ELEMENT ID")

now that is all over , you can initialize a instance of auto complete though javascript all the time. Just make sure the ID already does not exist.

Deeptechtons
  • 10,945
  • 27
  • 96
  • 178
  • Apparently AjaxControlToolkit is now Sys.Extended.UI, so $create(AjaxControlToolkit.AutoCompleteBehavior, ..., ..., ..., ...); would be $create(Sys.Extended.UI.AutoCompleteBehavior, ..., ..., ..., ...); – user1566694 Nov 25 '14 at 17:39
0

Apparently Microsoft didn't think was important, so there is not a way to do this at this time :)

Techgration
  • 516
  • 4
  • 16