ASP.NET - Ajax Autocomplete extender not calling webservice webmethod

Asked By p on 28-Jan-12 04:28 AM
'm using ajax autocomplete extender but my webservicemethod not calling it goes to webservice file but does'nt call the webmethod

Here is my code:


<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtname"

CompletionInterval="100" CompletionSetCount="10"

MinimumPrefixLength="2" EnableCaching="false" ServicePath="WebService.asmx"

ServiceMethod="GetSuggestion" >

</cc1:AutoCompleteExtender>






[System.Web.Script.Services.ScriptService]

public class WebService : System.Web.Services.WebService

{

clsConnection ObjConn;

SqlCommand SqlComm;

SqlConnection SqlConn;

public WebService ()

{

//Uncomment the following line if using designed components

//InitializeComponent();

}

[WebMethod]

public string HelloWorld()

{

return "Hello World";

}


[

WebMethod]

[System.Web.Script.Services.ScriptMethod]

public string[] GetSuggestion(string PrefixText, int count)

{

List<string> name = new List<string>();

string connString = "";

ObjConn = new clsConnection();

SqlConn =

new SqlConnection();

try

{

connString = ObjConn.connectionstring();

SqlConn.ConnectionString = connString;

SqlComm = new SqlCommand("name", SqlConn);

SqlComm.CommandType =

CommandType.StoredProcedure;

SqlComm.Parameters.AddWithValue("@p_search_text", PrefixText);

SqlConn.Open();


using (SqlDataReader dr = SqlComm.ExecuteReader())

{

while (dr.Read())

{


string item = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dr["name"].ToString(), dr["id"].ToString());

name.Add(item);

}

dr.Close();

}

SqlConn.Close();

}

catch

{

}

return name.ToArray();

}


}

kalpana aparnathi replied to p on 28-Jan-12 04:39 AM
hi,

please remove comment from web service.and write code you want inside the web service.and also check you import file for web service

like this:

Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Web.Script.Services
Imports System.ComponentModel



Thanks,

D Company replied to p on 28-Jan-12 04:46 AM
hello friend,

i can not see below line of code in your posted code segment, which is required to call a webservice.

<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
if it is already added follow these fix.

http://

http://


Regards
D
Riley K replied to p on 28-Jan-12 04:46 AM


Try to mention the webmethod like this and see

[WebMethod]

public string[] GetSuggestion(string PrefixText, int count)

Reena Jain replied to p on 28-Jan-12 04:55 AM
Hi,

To use web service of AutoComplete Textbox,  ASP.NET AJAX extender that can be attached to any TextBox control. When the user types some letters in the Textbox, a popup panel will come to action and displayed the related words. So that the user can choose exact word from the popup panel.This AutoComplete fetches data from the database through a Webservice.

here is a good link on this
http://www.aspdotnetcodes.com/AutoComplete_From_Database.aspx

Hope this will help you
dipa ahuja replied to p on 28-Jan-12 06:04 AM
Step 1 : Take a TextBox , AutoCompleteExtender
 
<asp:TextBox runat="server" ID="txtInput" Width="300" />
<cc1:AutoCompleteExtender runat="server" ID="AutoComplete1"
TargetControlID="txtInput"
ServiceMethod="GetNames"
ServicePath="WebService.asmx"
MinimumPrefixLength="1"
CompletionInterval="1000"
EnableCaching="true"
CompletionSetCount="20"/>
 
Step 2 : Add ScriptManager on page with <Services> tag
 
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
  <asp:ServiceReference Path="~/WebService.asmx" />
</Services>
</asp:ScriptManager>
 
Step 3: Add a Webservice file in your website by Right click on website->Add new Item ->Web Service and add this code inside it..
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web.Services;
 
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
 
public class WebService : System.Web.Services.WebService
{
  public WebService()
  {
  }
 
  [WebMethod]
  public string[] GetNames(string prefixText, int count)
  {
    List<string> items = new List<string>(count);
    DataSet ds = new DataSet();
 
    string cs = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
    using (SqlConnection connection = new SqlConnection(cs))
    {
        string sql = "SELECT name FROM people WHERE name LIKE '" + prefixText + "%'";
      SqlDataAdapter adapter = new SqlDataAdapter();
      adapter.SelectCommand = new SqlCommand(sql, connection);
      adapter.Fill(ds);
    }
 
    foreach (DataRow dr in ds.Tables[0].Rows)
    {
      items.Add(dr["name"].ToString());
    }
 
    return items.ToArray();
  }
}