Wednesday, July 22, 2009

AutoCompleteExtender problem in Update Panel

I was working with AutoComplete for TextBoxes and problem started when i put these autocomplete in Update Panel

Two components with the same id PopupBehavior' can't be added to the application

After every postback i was getting this java script error.

After a lot of investigation i found the solution

Suppose you have an autocomplete extender

< ajax Toolkit:AutoCompleteExtender
TargetControlID="myTextBox"
ServiceMethod="GetCompletionList"
ServicePath="AutoComplete.asmx"
MinimumPrefixLength="2"
CompletionInterval="1000"
EnableCaching="true"
CompletionSetCount="20" >
< /a jax Toolkit: Auto CompleteExtender>'



You have do some trick in Page Load

Public void page_load()
{
autocomplete1.ID= System.DateTime.Now.ToString();
}

So now every time your control will get new ID and you won't get any javascript error.

If anyone have any different solution, Please post it here