Please refer this code.
Make sure your webservice name and service method name are correct. Also please check the function prototype. Share keyword will not be there in the WebService methods(static for C#).
HTML
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
body
{
font-family: Arial;
font-size: 10pt;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<cc1:ToolkitScriptManager runat="server">
</cc1:ToolkitScriptManager>
<asp:TextBox ID="txtContactsSearch" runat="server"></asp:TextBox>
<cc1:AutoCompleteExtender ID="AutoCompleteEx" runat="server" EnableCaching="true"
BehaviorID="AutoCompleteEx" MinimumPrefixLength="2" TargetControlID="txtContactsSearch"
ServicePath="~/Pages/MyService.asmx" ServiceMethod="SearchCustomers" CompletionInterval="1000"
CompletionSetCount="20">
</cc1:AutoCompleteExtender>
</div>
</form>
</body>
</html>
Namespaces
using System.Web.Services;
using System.Data.SqlClient;
using System.Configuration;
VB.Net From WebService
<System.Web.Services.WebMethod> _
Public Function SearchCustomers(prefixText As String, count As Integer) As List(Of String)
Using conn As New SqlConnection()
conn.ConnectionString = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using cmd As New SqlCommand()
cmd.CommandText = "select ContactName from Customers where " + "ContactName like @SearchText + '%'"
cmd.Parameters.AddWithValue("@SearchText", prefixText)
cmd.Connection = conn
conn.Open()
Dim customers As New List(Of String)()
Using sdr As SqlDataReader = cmd.ExecuteReader()
While sdr.Read()
customers.Add(sdr("ContactName").ToString())
End While
End Using
conn.Close()
Return customers
End Using
End Using
End Function
C#
[System.Web.Services.WebMethod()]
public List<string> SearchCustomers(string prefixText, int count)
{
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select ContactName from Customers where ContactName like @SearchText + '%'";
cmd.Parameters.AddWithValue("@SearchText", prefixText);
cmd.Connection = conn;
conn.Open();
List<string> customers = new List<string>();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
customers.Add(sdr["ContactName"].ToString());
}
}
conn.Close();
return customers;
}
}
}
Screenshot
![](https://i.imgur.com/RV1DArV.png)
Output
![](https://i.imgur.com/Rz2S4og.png)