日期:2014-05-16  浏览次数:20774 次

很简单的AutoCompleteExtender不触发问题
这是页面代码
HTML code

<%@ 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">
    <div>
      <asp:ScriptManager ID="d1" runat="server">
      <Services>
        <asp:ServiceReference  Path="~/WebService.asmx"/>
      </Services>
      </asp:ScriptManager>
        <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
                <ajax:AutoCompleteExtender
                 runat="server"
                TargetControlID="TextBox1" 
                MinimumPrefixLength="1" 
                ServicePath="WebService.asmx" 
                ServiceMethod="GetHotSearchKeywords">      
                </ajax:AutoCompleteExtender>
    </div>
    </form>
</body>
</html>


asmx文件
C# code
<%@ WebService Language="C#" CodeBehind="~/App_Code/WebService.cs" Class="WebService" %>


后台文件.. 
我在方法出打了断点 不会执行 这是为什么阿 谢谢大家
C# code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

/// <summary>
///WebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 
 [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService 
{
     public static string[] GetHotSearchKeywords(string keyword, int displaycount)
    {
        return Class2.GetHotSearchKeywords(keyword, displaycount);
    }   
}



------解决方案--------------------
HTML code

错误1:
<ajax:AutoCompleteExtender
                 runat="server"
                TargetControlID="TextBox1" 
                MinimumPrefixLength="1" 
                ServicePath="WebService.asmx" 
                ServiceMethod="GetHotSearchKeywords"
                CompletionSetCount="10">      
                </ajax:AutoCompleteExtender>
错误2:
[WebMethod]
public static string[] GetHotSearchKeywords(string keyword, int displaycount)
    {
        return Class2.GetHotSearchKeywords(keyword, displaycount);
    }