我想在TextBox中使用AutoCompleteExtender进行自动完成。但没有得到结果。我使用了以下语法: 在aspx page ::
中<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然后单击“调用”按钮时,我得到了正确的结果。我该如何解决?
答案 0 :(得分: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>