Click here to Skip to main content
15,996,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

XML
<asp:ScriptManager ID="mgr" runat="Server">
      <Services>
        <asp:ServiceReference Path="~/AutoComplete.asmx" />
      </Services>
    </asp:ScriptManager>



AutoComplete Extender:

XML
<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.
Posted

1 solution

Let me gues :)
you are swallowing exceptions, remove the try catch block and deploy the application again. Then you can see the exception and find solution for that.
most probably there can be a issue related to OLEDB driver and access database file, permission issue etc..
Why access database? you better move to SQL express, SQlite or some other database server.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900