Monday, March 26, 2012

AJAX AutoComplete not completing text?

Hi

The AJAX AutoComplete is not returning any values when users type in text in the TextBox1.

Here is my ASPX code:

<%@dotnet.itags.org.PageLanguage="C#"AutoEventWireup="true"CodeFile="Test.aspx.cs"Inherits="Test" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title>Untitled Page</title>

</head>

<body>

<formid="form1"runat="server">

<div>

<asp:ScriptManagerID="ScriptManager1"runat="server">

<Services>

<asp:ServiceReferencePath="~/DynamboWebService.asmx"/>

</Services>

</asp:ScriptManager>

<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>

<ajaxToolkit:AutoCompleteExtenderID="AutoCompleteExtender1"runat="server"TargetControlID="TextBox1"ServicePath="~/DynamboWebService.asmx"ServiceMethod="GetProvincesStates"CompletionSetCount="3"MinimumPrefixLength="2">

</ajaxToolkit:AutoCompleteExtender>

</div>

</form>

</body>

</html>

This is my Web Service Code (DynamboWebService.asmx):

using System;

using System.Web;

using System.Collections;

using System.Web.Services;

using System.Web.Services.Protocols;

using System.Web.UI.WebControls;

using System.Configuration;

using System.Security;

using System.Data;

using System.Data.Sql;

using System.Data.SqlClient;

using System.IO;

using System.Net.Mail;

using System.Collections.Generic;

///<summary>

/// Summary description for DynamboWebService

///</summary>

[WebService(Namespace ="http://tempuri.org/")]

[WebServiceBinding(ConformsTo =WsiProfiles.BasicProfile1_1)]

publicclassDynamboWebService : System.Web.Services.WebService {

public DynamboWebService () {

//Uncomment the following line if using designed components

//InitializeComponent();

}

[System.Web.Services.WebMethod]

[System.Web.Script.Services.ScriptMethod]

publicstring[] GetProvincesStates(string prefixText,int count)

{

if (count == 0)

{

count = 10;

}

if (prefixText.Equals("xyz"))

{

returnnewstring[0];

}

Random random =newRandom();

List<string> items =newList<string>(count);

//Usually, here is a sqlstate to get some records.

for (int i = 0; i < count; i++)

{

char c1 = (char)random.Next(65, 90);

char c2 = (char)random.Next(97, 122);

char c3 = (char)random.Next(97, 122);

items.Add(prefixText + c1 + c2 + c3);

}

return items.ToArray();

}

}

Does anyone have any suggestions? I am pretty sure the Web Service is functioning and returning values.

Thanks for your help in advance.

Regards
Edward

Hi,

Please change:

[WebService(Namespace ="http://tempuri.org/")]

[WebServiceBinding(ConformsTo =WsiProfiles.BasicProfile1_1)]

publicclassDynamboWebService : System.Web.Services.WebService {

public DynamboWebService () {

//Uncomment the following line if using designed components

//InitializeComponent();

}

[System.Web.Services.WebMethod]

[System.Web.Script.Services.ScriptMethod]

publicstring[] GetProvincesStates(string prefixText,int count)

To:

[WebService(Namespace ="http://tempuri.org/")]

[WebServiceBinding(ConformsTo =WsiProfiles.BasicProfile1_1)]

[System.Web.Script.Services.ScriptService]

publicclassDynamboWebService : System.Web.Services.WebService {

public DynamboWebService () {

//Uncomment the following line if using designed components

//InitializeComponent();

}

[System.Web.Services.WebMethod]

publicstring[] GetProvincesStates(string prefixText,int count)

,then it should work.

And you don't need:

<Services>

<asp:ServiceReferencePath="~/DynamboWebService.asmx"/>

</Services>

Best Regards,


Hi Thanks for your help - it worked!

Now I encountered another problem all of a sudden:

I'm using:

ASP.NET 2 Wizard Control inside an Update Panel

Don't worry, found the problem: Both AutoComplete Extenders had the sameBehaviorID

No comments:

Post a Comment