Hi Guys,
I cant understand why my textbox is doing nothing. I want a TextBox that would search a database and give suggestions based on what the user types on every keystroke. After doing some research, i realized that you had to use webservice and so that is what i did.
Here is the simple form with a textbox,scriptm anager and an Autocomplete extender
And here is the webservice
I know the webservice by itself is working becuse i set that as the start page and run the program and invoked the webservice and it gave me the correct answers
Somehow I dont know how the form is calling the webservice because nothing seems to be happening
Can someone please help me?
I cant understand why my textbox is doing nothing. I want a TextBox that would search a database and give suggestions based on what the user types on every keystroke. After doing some research, i realized that you had to use webservice and so that is what i did.
Here is the simple form with a textbox,scriptm anager and an Autocomplete extender
Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="AutoCompleteTest.asmx" />
</Services>
</asp:ScriptManager>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><div>
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" MinimumPrefixLength="1" ServiceMethod="GetCentreNumbers" ServicePath="~\AutoCompleteTest.asmx" TargetControlID="TextBox1">
</cc1:AutoCompleteExtender>
</div>
</form>
</body>
</html>
Code:
<%@ WebService Language="C#" Class="AutoCompleteTest" %>
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
[System.Web.Script.Services.ScriptService()]
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class AutoCompleteTest : System.Web.Services.WebService {
[System.Web.Script.Services.ScriptMethod]
[WebMethod]
public string[] GetCentreNumbers(string PrefixText)
{
string sql = "Select * from Centre Where centreNo like @PrefixText";
SqlDataAdapter da = new SqlDataAdapter(sql,ConfigurationManager.ConnectionStrings["DBConnect"].ToString());
da.SelectCommand.Parameters.Add("@PrefixText", SqlDbType.VarChar, 50).Value = PrefixText+ "%";
DataTable dt = new DataTable();
da.Fill(dt);
string[] items = new string[dt.Rows.Count];
int i = 0;
foreach (DataRow dr in dt.Rows)
{
items.SetValue(dr["centreNo"].ToString(),i);
i++;
}
return items;
}
}
Somehow I dont know how the form is calling the webservice because nothing seems to be happening
Can someone please help me?
Comment