Hello. I have a ajax autocomplete extender and everything works fine. I mean sql procedure and others are fine but when I enter something to textbox nothing happened. Why is that?
Here is my codes.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Configuration;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
/// <summary>
/// Summary description for WebService
/// </summary>
[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 WebService : System.Web.Services.WebService {
string[] arr;
public WebService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string[] testing(string prefixText)
{
if (prefixText.Length > 0)
{
string sql = "Select * From titles Where title like @title";
SqlDataAdapter da = new SqlDataAdapter(sql, "myconnectionstring is here");
da.SelectCommand.Parameters.Add("@title", 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["title"].ToString(), i);
i++;
}
return items;
}
arr[0] = "";
return arr;
}
}
Html side:
<%@ Page Title="" Language="C#" MasterPageFile="~/adminpanel/adminpanel.master" AutoEventWireup="true" CodeFile="autocomplete.aspx.cs" Inherits="adminpanel_autocomplete" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
MinimumPrefixLength="1" ServiceMethod="testing" ServicePath="WebService.asmx" TargetControlID="TextBox1" Enabled="true">
</asp:AutoCompleteExtender>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>