的修正: 缺失物业CompletionInterval =“0”
我正在测试ajax autocomplete extender和webservices的功能。并发现自动完成扩展程序需要一段时间才能获取数据并显示。我目前没有数据库连接或类似的东西。我只是将所有项目放在webservice函数中的数组中,并使用LINQ返回匹配的项目集。显示数据的差距大约为1秒。我尝试打开/关闭EnableCaching,我发现有人在博客上建议,但是比较谷歌搜索数十亿数据并在实时网站上返回结果,数十亿用户没有一秒钟延迟,这仍然很慢。 / p>
虽然Google不会使用asp.net,Linq或脚本管理器来进行Ajax工作,但我只是在我的本地计算机上进行测试,没有数据库连接,我认为必须有一种方法可以让它更快地运行。可能我错过了设置某个地方的设置。这是我的代码。
ASPX
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:TextBox ID="TextBox1" runat="server" Width="200px"></asp:TextBox>
<asp:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server" ServiceMethod="HelloWorld" MinimumPrefixLength="1" EnableCaching="false" CompletionListCssClass="CompletionListCssClass"
DelimiterCharacters="" Enabled="True" ServicePath="WebService.asmx" TargetControlID="TextBox1">
</asp:AutoCompleteExtender>
<br />
<asp:Button ID="Button1" runat="server" Text="Search" />
code_behind上没有任何内容。
以下是webservice的代码..
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class WebService
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function HelloWorld(prefixText As String) As String()
Dim str() As String = {"Afghanistan", "Albania", "Algeria", "Andorra", "Angola", "Antigua and Barbuda", "Argentina", "Armenia", "Australia", "Austria", "Azerbaijan",
"Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "Brunei",
"Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Central African Republic",
"Chad", "Chile", "China", "Colombi", "Comoros", "Congo (Brazzaville)", "Congo", "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba", "Cyprus",
"Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "East Timor (Timor Timur)", "Ecuador", "Egypt", "El Salvador",
"Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Fiji", "Finland", "France", "Gabon", "Gambia, The", "Georgia", "Germany", "Ghana",
"Greece", "Grenada", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Honduras", "Hungary", "Iceland", "India", "Indonesia",
"Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea, North",
"Korea, South", "Kuwait", "Kyrgyzstan", "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania",
"Luxembourg", "Macedonia", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Mauritania", "Mauritius",
"Mexico", "Micronesia", "Moldova", "Monaco", "Mongolia", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru", "Nepa", "Netherlands",
"New Zealand", "Nicaragua", "Niger", "Nigeria", "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay",
"Peru", "Philippines", "Poland", "Portugal", "Qatar", "Romania", "Russia", "Rwanda", "Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent",
"Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia and Montenegro", "Seychelles", "Sierra Leone", "Singapore",
"Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "Spain", "Sri Lanka", "Sudan", "Suriname", "Swaziland", "Sweden", "Switzerland",
"Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "Togo", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Tuvalu", "Uganda",
"Ukraine", "United Arab Emirates", "United Kingdom", "United States", "Uruguay", "Uzbekistan", "Vanuatu", "Vatican City", "Venezuela", "Vietnam",
"Yemen", "Zambia", "Zimbabwe"}
Dim result As ArrayList = Nothing
Dim query = From x In str
Where x.ToLower.Contains(prefixText)
Select x
Return query.ToArray
End Function
End Class
答案 0 :(得分:3)
AutoCompleteExtender中是否有延迟属性? CompletionInterval我想。
答案 1 :(得分:0)
正确的方法是添加CompletionInterval="xxx"
,其中xxx是超时(以毫秒为单位)。 (工具是我对ajaxtools的定义)
<asp:TextBox runat="server" ID="Search" CssClass="search" AutoPostBack="true" />
<Tools:AutoCompleteExtender
ID="Search_AutoCompleteExtender"
runat="server"
CompletionInterval="250"
MinimumPrefixLength="3"
DelimiterCharacters=""
ServiceMethod="GetCompletionKeyList"
ServicePath="Keys.Aspx"
Enabled="True"
CompletionListCssClass="CompletionListCssClass"
CompletionListItemCssClass="CompletionListItemCssClass"
CompletionListHighlightedItemCssClass="CompletionListHighlightedItemCssClass"
TargetControlID="Search"/>
在代码VB后面
<System.Web.Services.WebMethod>
<System.Web.Script.Services.ScriptMethod()>
Public Shared Function GetCompletionKeyList(prefixText As String, count As Integer) As String()
return {"Your", prefixText, "selection" }
end Function