TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
sonal thosar
NA
18
52.1k
Autocompleteextender not working
Jul 12 2011 10:10 AM
Hi All,
I am beginner to ajax control. I am using AutoCompleteExtender Textbox. My project is not showing any error. It compiled successfully but textbox not displaying any autocomplete suggestions as i type.
Please tell me whats the error. I am using asp.net 3.5.
Here is Code :
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">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
<Services>
<asp:ServiceReference path="~/AutoCompleteTextBox.asmx" />
</Services>
</asp:ToolkitScriptManager>
<div>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<br />
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" EnableCaching="true" TargetControlID="txtName" ServicePath="AutoCompleteTextBox.asmx" ServiceMethod="getProductList" MinimumPrefixLength="2" UseContextKey="false">
</asp:AutoCompleteExtender>
</div>
</form>
</body>
</html>
WebService :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
/// <summary>
/// Summary description for AutoCompleteTextBox
/// </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 AutoCompleteTextBox : System.Web.Services.WebService {
//public AutoCompleteTextBox () {
//Uncomment the following line if using designed components
//InitializeComponent();
//}
[WebMethod]
public string[] getProductList( string prefixText)
{
string conString = WebConfigurationManager.ConnectionStrings["Northwind"].ConnectionString;
SqlConnection con = new SqlConnection(conString);
string strQuery = "Select ProductName From Products Where ProductName LIKE '" + prefixText + "%'";
SqlCommand cmd = new SqlCommand(strQuery, con);
con.Open();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
string[] countName = new string[ds.Tables[0].Rows.Count];
int i = 0;
try
{
foreach(DataRow dr in ds.Tables[0].Rows)
{
countName.SetValue(dr["ProductName"].ToString(),i);
i++;
}
}
catch(Exception err)
{
throw err;
}
finally{con.Close();}
return countName;
}
}
Reply
Answers (
2
)
Want to study AJAX
Want to hide modalpopup control at cancel button