【问题标题】:AutoCompleteExtender is not working for a TextBoxAutoCompleteExtender 不适用于 TextBox
【发布时间】:2012-03-24 17:28:33
【问题描述】:

我想在 TextBox 中使用 AutoCompleteExtender 进行自动完成。但没有得到结果。我使用了以下语法: 在 aspx 页面中::

<asp:scriptmanager EnablePageMethods="true" runat="server"></asp:scriptmanager>

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

<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" 
Enabled="true" EnableCaching="true" MinimumPrefixLength="1" 
ServiceMethod="GetNames" ServicePath="~/Autocomplete.asmx"
TargetControlID="txtautocomplete" runat="server">
</cc1:AutoCompleteExtender>

在 Autocomplete.asmx ::

    [WebMethod]
    [ScriptMethod()]
    public static string[] GetNames(string prefixText, int count)
    {
        ArrayList sampleList = new ArrayList();

        sampleList.Add("ABC"); sampleList.Add("Hello");

        sampleList.Add("Hi"); sampleList.Add("Apple");

        sampleList.Add("Hey");

        ArrayList filteredList = new ArrayList();
        foreach (string s in sampleList)
        {
            if (s.ToLower().StartsWith(prefixText.ToLower()))

                filteredList.Add(s);
        }
        return (string[])filteredList.ToArray(typeof(string));
    }

当我直接运行 Autocomplete.asmx 然后单击 Invoke 按钮时,我得到了正确的结果。我该如何解决?

【问题讨论】:

    标签: c# asp.net autocomplete ajaxcontroltoolkit


    【解决方案1】:

    您是否尝试过像这样在 web.config 中配置端点:

    <system.serviceModel>
      <behaviors>
        <endpointBehaviors>
          <behavior name="ServiceAspNetAjaxBehavior">
            <enableWebScript/>
          </behavior>
        </endpointBehaviors>
      </behaviors>
      <serviceHostingEnvironment aspNetCompatibilityEnabled="true">
        <baseAddressPrefixFilters>
          <add prefix="http://rrdb.dev"/>
        </baseAddressPrefixFilters>
      </serviceHostingEnvironment>
      <services>
        <service name="Service">
          <endpoint address="" behaviorConfiguration="ServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="Service"/>
        </service>
      </services>
      <bindings>
    </system.serviceModel>
    

    http://msdn.microsoft.com/en-us/library/bb628467.aspx

    【讨论】:

      猜你喜欢
      • 2020-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-01
      相关资源
      最近更新 更多