I have just started using this toolkit and it is great, but I stubled upon a problem when I was trying to make a web user control containing a textbox and a autocompleteextender.
To reproduce, follow these steps:
1. Create a new website using the AJAX Control Toolkit Web Site template. Verify you choose c# as language
2. Add a web user control to your project
3. Add a textbox to the web user control
4. Add a autocompleteextender to the web user control
5. Set the TargetControlID setting for the autocompleteextender to point at the textbox you added in step 3.
6. In designmode, click the white arrow on the autocompleteextender in designmode and click "Add autocomplete page method".
7. Paste this code inside your new method created by step 6.
WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static
string[] GetCompletionList(string prefixText,
int count, string contextKey)
{
string[] result =
new string[3];
result[0] = prefixText + "a";
result[1] = prefixText + "aa";
result[2] = prefixText + "aaa";
return result;
}
8. Open default.aspx in designmode and drag-and-drop your web user control onto the form (after the toolkitscriptmanager).
9. Run the website and notice that the autocompletextender does not work.
Am I doing something wrong or is this a bug? If I skip the step of creating a web user control and put the textbox and autocomplete extender onto the default.aspx page directly the autocompleteextender works like a charm.
"A callable page method is a public static (or Shared in Visual Basic® .NET) method defined in the codebehind class and decorated with the same WebMethod attribute used for Web service methods. At present, this is
limited to ASPX pages-both inline and codebehind code-but might be extended in the future to user controls and custom controls."
I haven't verified that this still applies. It might have changed but I doubt it.
So, either put the GetCompletionList in the aspx page or create a web service.
The web service returns a string[] and takes as parameters 3 strings: prefixText, count and contextKey. This is only because ive read on AutoComplete sample that it has to be this way.
ScriptService]
public class
AutoComplete : System.Web.Services.WebService {
public AutoComplete () {
[System.Web.Services.WebMethod]
public string[] GetCompletionList(string prefixText,
int count)
Per Edgren
Member
1 Points
2 Posts
AutoCompleteExtender does not work in a web user control
Oct 17, 2007 09:40 AM|LINK
Hi!
I have just started using this toolkit and it is great, but I stubled upon a problem when I was trying to make a web user control containing a textbox and a autocompleteextender.
To reproduce, follow these steps:
1. Create a new website using the AJAX Control Toolkit Web Site template. Verify you choose c# as language
2. Add a web user control to your project
3. Add a textbox to the web user control
4. Add a autocompleteextender to the web user control
5. Set the TargetControlID setting for the autocompleteextender to point at the textbox you added in step 3.
6. In designmode, click the white arrow on the autocompleteextender in designmode and click "Add autocomplete page method".
7. Paste this code inside your new method created by step 6.
string[] result = new string[3];result[0] = prefixText + "a";
result[1] = prefixText + "aa";
result[2] = prefixText + "aaa";
return result;
Now the code should now look like this:
[System.Web.Services.
WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]public static string[] GetCompletionList(string prefixText, int count, string contextKey)
{
string[] result = new string[3];
result[0] = prefixText + "a";
result[1] = prefixText + "aa";
result[2] = prefixText + "aaa";
return result;
} 8. Open default.aspx in designmode and drag-and-drop your web user control onto the form (after the toolkitscriptmanager).
9. Run the website and notice that the autocompletextender does not work.
Am I doing something wrong or is this a bug? If I skip the step of creating a web user control and put the textbox and autocomplete extender onto the default.aspx page directly the autocompleteextender works like a charm.
Please advice!
Regards
Per
autocomplete ajax extender toolkit autocompleteextender
TCavins
Member
718 Points
213 Posts
Re: AutoCompleteExtender does not work in a web user control
Oct 17, 2007 12:27 PM|LINK
Make sure the Service Path is pointing to the relative location of the ascx file. That is usually what I've found the issue to be.
Tim
Hocke
Member
128 Points
15 Posts
Re: AutoCompleteExtender does not work in a web user control
Oct 17, 2007 12:57 PM|LINK
According to Dino Esposito in MSDN Magazine Feb 2007:
I haven't verified that this still applies. It might have changed but I doubt it.
So, either put the GetCompletionList in the aspx page or create a web service.
Per Edgren
Member
1 Points
2 Posts
Re: AutoCompleteExtender does not work in a web user control
Oct 17, 2007 01:23 PM|LINK
Thank you Hocke!
I put the methods in the aspx page and everything worked!
ale.nagy
Member
4 Points
2 Posts
Re: AutoCompleteExtender does not work in a web user control
Oct 17, 2007 03:47 PM|LINK
I have created a WebService and still no luck.
The tree of elements i´m handling is:
<ASPX Page>
<UserControl>
<Autocomplete ServicePath="~/WebServices/ServiceName.asmx">
</UserControl>
</ASPX Page>
<WebService>
</WebService>
The web service returns a string[] and takes as parameters 3 strings: prefixText, count and contextKey. This is only because ive read on AutoComplete sample that it has to be this way.
Any ideas would be most welcome.
ale.nagy
Member
4 Points
2 Posts
Re: AutoCompleteExtender does not work in a web user control
Oct 17, 2007 05:57 PM|LINK
Ok. I´ve found what was missing.
WebService must be marked with [ScriptService] attribute AND AutoComplete MUST have
ContextKey="false" set...it seems its not the default ...
doWhileSomet...
Member
26 Points
15 Posts
Re: AutoCompleteExtender does not work in a web user control
Dec 01, 2007 01:55 AM|LINK
I Just thought I would add the exact markup for those still in need. It was my first time using the AC extender and ran into the same problem.
C#[
WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)][System.Web.Script.Services.
ScriptService] public class AutoComplete : System.Web.Services.WebService { public AutoComplete () { [System.Web.Services.WebMethod] public string[] GetCompletionList(string prefixText, int count)Hope this sheds a brighter light on the subject.
Regards, Do-
autocompleteextender ajaxtoolkit