Problem in ajax autocomplete extender control for textbox?

Posted by Prabu_Spark under ASP.NET AJAX on 12/26/2012 | Points: 10 | Views : 5042 | Status : [Member] | Replies : 12
Hi sir,
I developed one application that has ajax autocomplete extender control for textbox, but i cant
able to get suggestion from the web method. I attached the code for details. Kindly give me the solution
for this problem.

Default.aspx:
*****************************************
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>

</head>
<body>
<form id="form1" runat="server">
<div>

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<table align="center">
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Enter the Employee Name"></asp:Label>
</td>
<td>
<asp:TextBox ID="txt_ename" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txt_ename"
MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1" CompletionInterval="1000" ServiceMethod="GetName" ></asp:AutoCompleteExtender>
</td>
<td>
<asp:Button ID="Button1" runat="server" Text="Search" onclick="Button1_Click" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>


Default.cs:
*********************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;


public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> GetName(String prefix)
{

List<string> ename = new List<string>();
int count;
DataSet ds=new DataSet ();
databaseconnection db = new databaseconnection();
string query = "select ename from emp where ename like '" + prefix + "%'";
db.executequery(query, out ds, out count);

for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
ename.Add(ds.Tables[0].Rows[i][0].ToString());
}
return ename;
}
}

With regards,
J.Prabu.
[Email:prbspark@gmail.com]



Responses

Posted by: Nadh123 on: 12/26/2012 [Member] Starter | Points: 25

Up
0
Down
<asp:ScriptManager ID="ScriptManager1" runat="server"
EnablePageMethods = "true">
</asp:ScriptManager>


Mahendra
91-9908699686

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Guna27 on: 12/26/2012 [Member] Starter | Points: 25

Up
0
Down
Mention the column index or column name inside your web method.

still you didn't get the output change the return type as string[]
return (string[]) ename.ToArray(typeof(string));

Guna..............

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Chaithragm on: 12/27/2012 [Member] Starter | Points: 25

Up
0
Down
I have used the service method to use auto extender but its not working
 Download source file

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 1/12/2013 [Member] Starter | Points: 25

Up
0
Down
hey, prabhu
check my attachment as i implemented autocomplete extender in my applic. nd its working flawlessly...try this u will rock definitely....
warm regards
 Download source file

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 1/12/2013 [Member] Starter | Points: 25

Up
0
Down
hey @chaithgram have u mentoned service path and service method in ur autocomplete extender control

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 1/12/2013 [Member] Starter | Points: 25

Up
0
Down
hey prabhu use this
string query = "select ename from emp where ename like @ename + '%'";

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Chaithragm on: 1/14/2013 [Member] Starter | Points: 25

Up
0
Down
ya im using service method, in ur files its not taking the service reference...

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 1/14/2013 [Member] Starter | Points: 25

Up
0
Down
have a look on my previous attachment in this post...

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Chaithragm on: 1/15/2013 [Member] Starter | Points: 25

Up
0
Down
how to add web reference to the application

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 1/15/2013 [Member] Starter | Points: 25

Up
0
Down
add these two namspaces
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 1/15/2013 [Member] Starter | Points: 25

Up
0
Down
try that

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Snaveen on: 2/14/2014 [Member] Starter | Points: 25

Up
0
Down
Hi,

did you get any error..?

What type of issue are you facing using this code..?

Refer below sample link here i try to explain how to work with AutoCiomplete Extender in Ajax.

http://www.dotnetspider.com/resources/45209-Ajax-Auto-Complete-Without-WebServices-aspnet.aspx

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response