1

part of My aspx page

<asp:TextBox runat="server" id= "TextBox1"  ></asp:TextBox>
    <ajaxToolkit:AutoCompleteExtender
                runat="server" TargetControlID="TextBox1"
                MinimumPrefixLength="0" ServiceMethod="getAutoComplete()"
                ServicePath="nationality.aspx.cs"                  
                >

</ajaxToolkit:AutoCompleteExtender>

my aspx.cs code:

[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] getAutoComlete(string prefixText, int count, string contextKey)
{
     string[] a = { "11", "22", "33" };
     return a;
}

I am trying to make autocomplete . What am I doing wrong?

user2114177
  • 273
  • 1
  • 9
  • 18

2 Answers2

2
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
    public static string[] getAutoComplete(string prefixText, int count, string contextKey)
    {
string[] a = { "11", "22", "33" };
            return a;
    }

You are not using the samename function on the aspx page and the C# code :)

Hassan
  • 1,413
  • 1
  • 10
  • 12
  • Sorry Improved that `[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()] public static string[] getAutoComplete(string prefixText, int count, string contextKey) { string[] a = { "11", "22", "33" }; return a; } ` Still doesn't work – user2114177 Aug 05 '13 at 09:45
0

If you have your service code on same page of your control, then it will directly call your service code.

  try below,

//change asp page like this

<asp:TextBox runat="server" id= "TextBox1"  ></asp:TextBox>
    <ajaxToolkit:AutoCompleteExtender
                runat="server" TargetControlID="TextBox1"
                MinimumPrefixLength="0" ServiceMethod="getAutoComplete">
</ajaxToolkit:AutoCompleteExtender>

// change your .cs code as below

[System.Web.Services.WebMethod(true)]
public static string[] GetCompletionList(string prefixText, int count)
{
     string[] a = { "11", "22", "33" };
     return a;
}

Hope it helps.
Harshil Raval
  • 2,115
  • 1
  • 13
  • 10
  • Did doesn't work too but i don't understand this:'service code on same page of your control' is my control is on nationality.aspx and code on nationality aspx.cs there are on different pages? – user2114177 Aug 05 '13 at 10:15
  • I mean your service code is on code side, and control on design side of same page, then you don't need to specify service path. It will automatically call it. – Harshil Raval Aug 05 '13 at 10:32
  • ok. now remove this [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()] and add instead [System.Web.Services.WebMethod(true)]. Check updated code. May be now work. – Harshil Raval Aug 05 '13 at 10:34