Chintan

Chintan

  • NA
  • 11
  • 15.9k

ajax autocomplete not firing

Apr 2 2014 2:47 AM

Hi all,

I have a textbox with the autocompleteextender in VS2012 that is referencing a webservice. However, nothing I seem to do makes this work as no values are returned when I begin typing in the textbox. When I view the webservice in my browser and invoke it, it returns values so I know that my webservice works. Code below

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>

Design

<div class="col-sm-12" runat="server" id="regno" visible="false">
<div class="form-group has-success txtbx">
<label class="control-label" for="inputWarning2">Search by Student Name.</label>
<asp:TextBox type="text" CssClass="form-control" ID="txtregno" runat="server" AutoPostBack="true" OnTextChanged="txtregno_TextChanged" />
<asp:AutoCompleteExtender runat="server" ID="txtautostudentcurrent" MinimumPrefixLength="1" TargetControlID="txtregno" DelimiterCharacters="" CompletionInterval="500" CompletionSetCount="10" ServiceMethod="GetCompletionListPresent" ServicePath="~/studentcurrent.asmx"></asp:AutoCompleteExtender>
<span class="glyphicon glyphicon-search form-control-feedback"></span>
</div>
</div>

Webservice Part.

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 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 studentcurrent : System.Web.Services.WebService
{
[WebMethod]
public string[] GetCompletionListPresent(string prefixText, int count)
{

DataSet ds = new DataSet();// but it does not do one by one
DataTable dt = new DataTable();//it checks one by one
string a = System.Configuration.ConfigurationManager.ConnectionStrings["smsonline"].ToString();
SqlConnection thisConnection = new SqlConnection(a);
SqlCommand cmd = new SqlCommand();
cmd.Connection = thisConnection;
cmd.CommandType = CommandType.Text;

cmd.CommandText = "WITH clean_cte AS(select CASE " +
" when (CC.transfercert=0 and CC.promoted=0) then (RTRIM(SP.studentfirstname) + ' ' + RTRIM(SP.studentlastname))+ '/'+ " +
" CONVERT(varchar(10),RTRIM(Y.years)) + '/' + CONVERT(varchar(20),RTRIM(CL.classname))+ ' ' + UPPER(CC.secdiv) end as Details " +
" from TBL_Student_CurrentClassDet CC inner join TBL_Student_PersonalDetails SP on CC.regno = SP.regno inner join TBL_MasterYear Y on CC.yearid = Y.yearid " +
" inner join TBL_Student_ClassDetails CD on CC.regno = CD.regno inner join TBL_MasterClass CL on CC.classid = CL.classid where " +
" (SP.studentfirstname like @myParameter or SP.studentlastname like @myParameter or Y.years like @myParameter or CL.classname like @myParameter)) select * from clean_cte where Details is not null";

cmd.Parameters.AddWithValue("@myParameter", prefixText + "%");

try
{
thisConnection.Open();
cmd.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
}
catch (Exception ex)
{

}
finally
{
thisConnection.Close();
}
dt = ds.Tables[0];

//Then return List of string(txtItems) as result
List<string> txtname = new List<string>();
String dbValues;

foreach (DataRow row in dt.Rows)
{
//String From DataBase(dbValues)
dbValues = row["Details"].ToString();
dbValues = dbValues.ToLower();
txtname.Add(dbValues);
}

return txtname.ToArray();
}
}

[System.ComponentModel.ToolboxItem(false)]

I don't no what does this line does. when i commented it, nothing change.

My Webservice is not inside the App Code folder.. its Individual file. its in the parent folder.

eg: studentcurrent.asmx and my code file is studentcurrent.asmx.cs

The Event is not firing at all. Have Put the Breakpoint too.. but nothing is happening.. When I just run the webservice it works fine.. but thru autocompleteextender its not firing.

Please Help


Answers (5)