2012-03-07 29 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

相關問題