Answered by:
auto complete extender did not work in asp.net 4.5

Question
-
User-470894283 posted
Hi,
Please, can anyone give me idea or help me out why my auto complete extender is not working.
Thanks in advanced.
Here is my Frontend and ASMX
<ajax:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></ajax:ToolkitScriptManager><asp:TextBox ID="txtIng1" runat="server" CssClass="ddlbranch textboxradiuscolor" Width="250" Height="20"></asp:TextBox>
<ajax:AutoCompleteExtender ID="AutoCompleteExtender2" runat="server" TargetControlID="txtIng1"
MinimumPrefixLength="1" ServiceMethod="getProductList"
CompletionInterval="1000" ServicePath="~/WebServices/InvProduct.asmx"
CompletionSetCount="20" DelimiterCharacters=";, :"
ShowOnlyCurrentWordInCompletionListItem="true"
OnClientItemSelected="OnContactSelected"
CompletionListCssClass="completionlist" CompletionListHighlightedItemCssClass="completionlisthighlight"
CompletionListItemCssClass="completionlistitem">
</ajax:AutoCompleteExtender>using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
namespace POS.WebServices
{
/// <summary>
/// Summary description for InvProduct
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class InvProduct : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod(EnableSession = true)]
public string[] getProductList(string prefixText, int count)
{
string status = Session["status"].ToString();
string constatus = Session["conStatus"].ToString();
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings[constatus]);
//ADO.Net
DataSet ds = new DataSet();
DataTable dt = new DataTable();
// con.ConnectionString = strCn;
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
//prevent SQL injection--------//
cmd.CommandText = "select * from Inv_Product Join Branch b on b.BranchId= Inv_Product.BranchId Where InvProductName like @myParameter and Inv_Product.DeleteStatus = 'N' and b.DeleteStatus = 'N'";
cmd.Parameters.AddWithValue("@myParameter", "%" + prefixText + "%");
try
{
con.Open();
cmd.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
}
catch
{
}
finally
{
con.Close();
}
dt = ds.Tables[0];
//Then return List of string(txtItems) as result
List<string> txtItems = new List<string>();
String dbValues;
foreach (DataRow row in dt.Rows)
{
//String From DataBase(dbValues)
dbValues = row["InvProductName"].ToString();
dbValues = dbValues.ToLower();
txtItems.Add(dbValues);
}
return txtItems.ToArray();
}
}
}
Friday, May 8, 2015 6:34 AM
Answers
-
User61956409 posted
Hi Junior1012,
Thanks for your post.
Firstly, please make sure the ServicePath is correct.
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]Secondly, please uncomment the following code in your webservice to allow this Web Service to be called from script.
[System.Web.Script.Services.ScriptService]
Best Regards,
Fei Han
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, May 10, 2015 10:27 PM