ASP.Net C# AJAX AutoCompleteExtender

The AutoCompleteExtender does not seem to work

Page 1 of 1

2 Replies - 19809 Views - Last Post: 14 March 2009 - 06:29 PM Rate Topic: -----

#1 ttptg   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 13-March 09

ASP.Net C# AJAX AutoCompleteExtender

Posted 13 March 2009 - 11:54 AM

I hope I did not post this in the wrong section as I could not find an AJAX section and I am developing this using C#.

I have tried to use the AJAX AutoCompleteExtender in a project of mine and I have read a few tutorials about it as well as tried out a few different methods. The code below is the easiest that I could follow and it does not seem to work. Please help me in debugging it.

The authoring tool that I am using is VWD 2008 SP1 with SQL Server 2008 integrated.
My database is named data.mdf with the table that I would like to search named restaurant - field to search for "name".
My database connection string is DatabaseConnectionString.

Code in HTML MasterPage.master
<asp:ScriptManager ID="ScriptManager1" runat="server">
		<p>search for your platter~</p>
	<div id="search">
		<asp:UpdatePanel ID="UpdatePanel1" runat="server">
		<asp:Panel ID="searchfunction" runat="server" DefaultButton="btnSearch">
		<asp:TextBox ID="txtSearch" runat="server" AutoComplete="off"></asp:TextBox>
		<cc1:AutoCompleteExtender ID="txtSearch_AutoCompleteExtender" runat="server" 
			DelimiterCharacters="" Enabled="True" ServiceMethod="GetRestaurantName" 
			ServicePath="AutoComplete.asms" TargetControlID="txtSearch" UseContextKey="True" MinimumPrefixLength="1">
		<cc1:TextBoxWatermarkExtender ID="txtSearch_TextBoxWatermarkExtender" 
			runat="server" Enabled="True" TargetControlID="txtSearch" 
			WatermarkText="Search Splatter~" WatermarkCssClass="color">
			<asp:Button ID="btnSearch" runat="server" Text="" Visible="false"/>

The WebMethod code used in AutoComplete.asms.cs
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
/// <summary>

/// Summary description for AutoComplete

/// </summary>


[WebService(Namespace = "")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class AutoComplete : System.Web.Services.WebService
	public string[] GetRestaurantName(string prefixText)
		DataSet ds = new DataSet();
		SqlConnection sqlCon = new SqlConnection(ConfigurationManager.AppSettings["DatabaseConnectionString"]);
		string strSql = "SELECT name FROM restaurants WHERE name LIKE '" + prefixText + "%' ";
		SqlCommand sqlComd = new SqlCommand(strSql, sqlCon);
		SqlDataAdapter sqlAdpt = new SqlDataAdapter();
		sqlAdpt.SelectCommand = sqlComd;

		string[] restName = new string[dtst.Tables[0].Rows.Count];

		int i = 0;
			foreach (DataRow rdr in dtst.Tables[0].Rows)
				restName.SetValue(rdr["name"].ToString(), i);
	   catch { }
		return restName;

I have used the tutorial on in order to do the above and it does not work. The AutoComplete would not appear when I type something into the textbox.

Am I missing something?

Another method I have used in the Web Method (this webmethod is placed in MasterPage.master.cs instead) is as follows:
	public static string[] GetRestaurantNames(string prefixText, int count)
		RestaurantsDataContext db = new RestaurantsDataContext();
		return db.restaurants.Where(n => => =>;

By using the method above. I have to added a web service named restaurant.dbml into App_Code folder.

Yet this does not work too.

I wish someone here could guide me, I would really appreciate it as I have exhausted every other resources - I have tried over 3 methods, from following 100% to modifying and customizing each tutorials to suit my database, yet none of them worked.

Thanks in advance for reading this thread.

Is This A Good Question/Topic? 0
  • +

Replies To: ASP.Net C# AJAX AutoCompleteExtender

#2 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: ASP.Net C# AJAX AutoCompleteExtender

Posted 13 March 2009 - 12:17 PM

Moving to ASP.NET
Was This Post Helpful? 0
  • +
  • -

#3 doWhileSomething   User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 96
  • Joined: 08-January 09

Re: ASP.Net C# AJAX AutoCompleteExtender

Posted 14 March 2009 - 06:29 PM

Your references to the web service "appear" to be wrong. I'm not sure if there was a new extension introduced in 2008, hence why I said "appear".
But web services have an ".asmx" extension, not ".asms".

This by itself would not allow the auto complete extender to function. The other file "restaurant.dbml " is a linq to sql class and while I don't have any experience with Linq, I don't believe this is considered a web service.

Also, you can set break points on web services, just like any other class. So, you can do a check if your extender is even making it this far, assuming that file actually exists.

Honestly, tutorials are a great way to learn, i've benefited from them myself. But copying and pasting code from samples is a sure fire way to get something to break or simply not work.

I would create a blank project, a single page, drop a text box and the extender on the page. Create a generic service that returns a static list (removing any DB involvement) and set 2-3 break points at various intervals. Once you get a "shell" to work, then you can start adding all the fancy stuff.

Also, I believe the context has to be passed as a paramater to the service for this particular control to work, the webservice you have:
GetRestaurantName(string prefixText) only takes in the textbox value, not the context key.

Hope this helps :^:

This post has been edited by doWhileSomething: 14 March 2009 - 06:33 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1