Tearing my hair out - ASP.Net AJAX AutoComplete not working

Posted by Dave on Stack Overflow See other posts from Stack Overflow or by Dave
Published on 2009-08-20T14:32:28Z Indexed on 2010/04/29 14:47 UTC
Read the original article Hit count: 447

Filed under:
|
|

Hope someone can help with this. I've been up and down the web and through this site looking for an answer, but still can't get the Autocomplete AJAX control to work. I've gone from trying to include it in an existing site to stripping it right back to a very basic form and it's still not functioning. I'm having a little more luck using Page Methods rather than a local webservice, so here is my code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="droptest.aspx.cs" Inherits="droptest" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!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:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    	<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server">
    	</asp:ScriptManager>
    	<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" 
    		MinimumPrefixLength="1" ServiceMethod="getResults" 
    		TargetControlID="TextBox1">
    	</cc1:AutoCompleteExtender>
    </form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Script.Services;
using System.Web.Services;

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

    }

    [WebMethod]
    public string[] getResults(string prefixText, int count)
    {
    	string[] test = new string[5] { "One", "Two", "Three", "Four", "Five" };
    	return test;
    }
}

Tried to keep things as simple as possible, but all I get is either the autocomplete dropdown with the source of the page (starting with the <! doctype...) letter by letter, or in IE7 it just says "UNDEFINED" all the way down the list.

I'm using Visual Web Developer 2008 at the moment, this is running on Localhost. I think I've exhausted all the "Try this..." options I can find, everything from adding in [ScriptMethod] to changing things in Web.Config.

Is there anything obviously wrong with this code?

Only other thing that may be having an effect is in Global.asax I do a Context.RewritePath to rewrite URLs - does this have any effect on AJAX?

Thanks for any help you can give.

© Stack Overflow or respective owner

Related posts about c#

Related posts about autocomplete