我有问题自动编译扩展器我想在mmaster页面中使用autocompate。
ASPX代码
<div class="col-xs-12 col-sm-12 col-md-5 top-search-holder no-margin">
<div class="search-area">
<div class="control-group" style="background-color: white">
<asp:TextBox runat="server" ID="TxtArama" CssClass="search-field" placeholder="Aranacak Kelimeyi girin..."></asp:TextBox>
<asp:AutoCompleteExtender ID="TxtArama_AutoCompleteExtender"
runat="server"
DelimiterCharacters=""
Enabled="True"
ServiceMethod="GetProducts"
ServicePath="AutoComplate.asmx"
TargetControlID="TxtArama">
</asp:AutoCompleteExtender>
<a class="search-button" href="#" runat="server" onserverclick="Aramaci_OnServerClick"></a>
</div>
</div>
</div>
AutoComplate.asmx
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService()]
//[System.ComponentModel.ToolboxItem(false)]
public class AutoComplate : System.Web.Services.WebService
{
[WebMethod()]
[System.Web.Script.Services.ScriptMethod()]
public string[] GetProducts(string prefixText,int count)
{
DataTable DT = new DataTable();
ArrayList PN = new ArrayList();
DT = DbClass.GetDataTable("SELECT * FROM Products WHERE ProductName LIKE '%" + prefixText + "%'", "MySql");
if (DT.Rows.Count>0)
{
for (int i = 0; i < DT.Rows.Count; i++)
{
PN.Add(DT.Rows[i]["ProductName"].ToString());
}
}
return (string[]) (PN.ToArray(typeof (string)));
}
}
我输入单词调用方法获取数据但没有在文本框中看到下面的列表。 怎么了? 请帮忙。
答案 0 :(得分:1)
您似乎缺少toolscript manager标记:
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" EnablePageMethods="True" />
您可以将其放在autocompleteExtender上方。
答案 1 :(得分:1)
我认为您的网络方法根本没有被调用。 尝试从浏览器调用asmx文件,如下所示:
http://localhost/app1/Autocomplete.asmx
像这样更改你的html代码:
<asp:TextBox runat="server" ID="TxtArama" CssClass="search-field"></asp:TextBox>
<asp:AutoCompleteExtender MinimumPrefixLength="2" CompletionInterval="100" EnableCaching="false" CompletionSetCount="10" TargetControlID="TxtArama" BehaviorID="AutoCompleteEx" ID="AutoCompleteExtender1" ServicePath="~/AutoComplete.asmx" ServiceMethod="GetProducts" runat="server" FirstRowSelected="false" Enabled="True">
</asp:AutoCompleteExtender>
在文本框中输入第二个字符后,它应调用webmethod(MinimumPrefixLength =“2”)