1

这是c#.net 2.0。我正在使用一个母版页。AJAX AutocompleteExtender无法正常工作。 Web服务工作

  • WebService可以正常工作。
  • 我完全难住了。当我输入文本框时,没有任何反应。

文件:

EditTicket.aspx AutoComplete.asmx App_Code文件/ AutoComplete.cs

EditTicket.aspx:

 <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc2" %> 


     <asp:ScriptManager id="ScriptManager1" runat="server" EnablepageMethods="true"> 
     <Services> 
      <asp:ServiceReference Path="AutoComplete.asmx" /> 
     </Services> 
     </asp:ScriptManager> 

    <cc2:AutoCompleteExtender 
     runat="server" 
     ID="AutoCompleteExtender1" 
     ServicePath="AutoComplete.asmx" 
     ServiceMethod="AutoComplete2" 
     MinimumPrefixLength="1" 
     CompletionSetCount="12" 
     TargetControlID="TextBox3" 
     EnableCaching="True" > 
    </cc2:AutoCompleteExtender> 

<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> 

AutoComplete.asmx:

<%@ WebService Language="C#" CodeBehind="~/App_Code/AutoComplete.cs" Class="AutoComplete" %> 

AutoComplete.cs:

using System; 
using System.Web; 
using System.Collections; 
using System.Web.Services; 
using System.Web.Script.Services; 
using System.Web.Services.Protocols; 
using System.Collections.Generic; 
using System.Data.SqlClient; 
using System.Configuration; 
using System.Data; 


/// <summary> 
/// Summary description for AutoComplete 
/// </summary> 
[WebService(Namespace = "http://tempuri.org/")] 
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
[ScriptService] 
public class AutoComplete : System.Web.Services.WebService { 

    public AutoComplete() { 

     //Uncomment the following line if using designed components 
     //InitializeComponent(); 
    } 

    [WebMethod] 
    [ScriptMethod] 
    public string[] AutoComplete2(string prefixText,int count) 
    { 
     string conString = ConfigurationManager.ConnectionStrings["DB"].ConnectionString; 
     SqlConnection connection = new SqlConnection(conString); 
     connection.Open(); 
     SqlParameter prm; 
     string sql = "Select program_name FROM CM_Programs WHERE program_name LIKE @prefixText"; 
     SqlDataAdapter cmd = new SqlDataAdapter(sql, connection); 
     prm = new SqlParameter("@prefixText", SqlDbType.VarChar, 50); 
     prm.Value = prefixText+ "%"; 
     cmd.SelectCommand.Parameters.Add(prm); 
     DataTable dt = new DataTable(); 
     cmd.Fill(dt); 
     string[] items = new string[dt.Rows.Count]; 
     int i = 0; 
     foreach (DataRow dr in dt.Rows) 
     { 
      items.SetValue(dr["program_name"].ToString(),i); 
      i++; 
     } 
     connection.Close(); 
     return items; 
    } 
} 

回答

1

“没有任何反应”不是一个容易的描述继续。当你说什么都不会发生,你检查的是

  • 服务器代码正在热播的 Web服务?
  • 正在执行您的查询,并返回结果 ?
  • 您的物品阵列正在填充 正确吗?

如果“没有”是没有以上正在发生的事情,我会开始检查,有在页面上,您自动完成扩展正确渲染(检查出微量的页面控件)没有JavaScript错误。

+1

我能够自己运行web服务,并获得像我期望的数组中的自动完成的结果。这部分工作正常。最终结果是,我的网站不是一个AJAX网站开始,所以我不得不复制一个AJAX网站的web.config并与我的web.config合并。 – somacore 2009-04-09 18:34:17

+0

你能明确地发布你在web.config中改变了什么,因为我遇到了同样的问题吗? – Blerta 2009-08-11 08:24:08

1

尝试摆弄CompletionInterval属性。在过去,我使用过这个控件,并没有看到我期望的行为,直到我将CompletionInterval设置为更低的值。它默认为1000(ms),我会给它一个值为1的值,只是为了看看是否所有的东西都按照它应该的方式工作(并且womp的步骤应该有助于缩小发生通信问题的位置),如果它确实如此工作,继续增加价值,直到您达到有意义的值(1毫秒向服务器发送大量请求)。回报什么可行,什么不可行。