2012-03-07 33 views
0

我想在TextBox中使用AutoCompleteExtender进行自动完成。但没有得到结果。我已经使用的语法如下: 在aspx页面::AutoCompleteExtender不适用于TextBox

<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按钮我获得正确的结果。 我该如何解决它。任何帮助将不胜感激。提前致谢。

回答

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

+0

感谢@Elementenfresser我会尽快尝试。 – 2012-03-09 10:48:53

相关问题