I have used a autocomplete extender for autocomplete search on textbox. For this i have used a web service. When I run the code on local host everything runs fine. But when i upload the code online ajax autocomplete extender does not invoke web service method. Below is the code.
.aspx Page
<asp:ScriptManager ID="mgr" runat="Server">
<Services>
<asp:ServiceReference Path="~/AutoComplete.asmx" />
</Services>
</asp:ScriptManager>
AutoComplete Extender:
<asp:TextBox ID="txtKeyword1" runat="server" CssClass="search-field"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender
runat="server"
BehaviorID="autoComplete1"
ID="autoComplete1"
TargetControlID="txtKeyword1"
ServicePath="~/AutoComplete.asmx"
ServiceMethod="GetCompletionList2"
MinimumPrefixLength="1"
CompletionInterval="1000"
EnableCaching="true"
CompletionSetCount="10"
CompletionListCssClass="autocomplete_completionListElement"
CompletionListItemCssClass="autocomplete_listItem"
CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
DelimiterCharacters=";, :" OnClientPopulating="ShowProcessImage"
OnClientPopulated="HideProcessImage">
</ajaxToolkit:AutoCompleteExtender>
Web Service
using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Data;
using System.Data.OleDb;
using System.Collections.Generic;
using System.Web.Script.Services;
using System.Xml;
///
/// Summary description for AutoComplete
///
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 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 AutoComplete : System.Web.Services.WebService
{
public AutoComplete ()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld()
{
return "Hello";
}
[WebMethod]
public string[] GetCompletionList2(string prefixText, int count)
{
//ADO.Net
OleDbConnection cn = new OleDbConnection();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
//String strCn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\F\\Hella\\Force One\\Code\\Force One 14 May 2014\\HellaWarranty.mdb;";
String strCn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Websites\\HellaWarranty\\HellaWarranty.mdb;";
cn.ConnectionString = strCn;
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = cn;
cmd.CommandType = CommandType.Text;
//Compare String From Textbox(prefixText) AND String From Column in DataBase(CompanyName)
//If String from DataBase is equal to String from TextBox(prefixText) then add it to return ItemList
//-----I Defined a parameter instead of passing value directly to prevent sql injection--------//
cmd.CommandText = "SELECT * FROM CaseMaster where CaseCode like '" + prefixText + "%'";
//cmd.Parameters.AddWithValue("@Name", prefixText);
try
{
cn.Open();
cmd.ExecuteNonQuery();
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(ds);
}
catch
{
}
finally
{
cn.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["CaseCode"].ToString();
dbValues = dbValues.ToLower();
txtItems.Add(dbValues);
}
return txtItems.ToArray();
}
}
Can Anyone Help me with this.