我在文本框中有一个自动填充扩展程序,用于显示项目类别。当我打开页面时,扩展器工作正常。但是,如果我打开页面并停止对其进行处理,并且在一段时间(例如15至25分钟)后使用此扩展器,则该问题将不起作用,并且不会影响我的Web服务来加载数据,则会发生问题。我认为这是一些会话或缓存问题,但我没有发现实际上我的代码在哪里的任何提示。
下面是我的自动填充扩展程序代码和我的asmx服务代码:
<ajaxToolkit:AutoCompleteExtender
BehaviorID="AutoCompleteEx"
ID="aceItemCategory"
runat="server"
ServiceMethod="GetItemCategoryListData"
ServicePath="~/Services/NavigationService.asmx"
TargetControlID="txtItemCategory"
MinimumPrefixLength="1"
UseContextKey="false"
CompletionInterval="0"
EnableCaching="true"
CompletionSetCount="30"
FirstRowSelected="true"
CompletionListCssClass="AutoExtender"
CompletionListItemCssClass="AutoExtenderList"
CompletionListHighlightedItemCssClass="AutoExtenderHighlight"
CompletionListElementID="acItemCategoryList"
OnClientItemSelected="ItemCategorySelected">
</ajaxToolkit:AutoCompleteExtender>
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod(EnableSession = true)]
public string[] GetItemCategoryListData(string prefixText, int count)
{
DataTable dt = new DataTable();
DataColumn dc = new DataColumn("Name", typeof(String));
dt.Columns.Add(dc);
DataRow dr = dt.NewRow();
dt.Rows.Add(dr);
//DataTable dt = null;
DataView dv = null;
List<string> suggestions = new List<string>();
dt = (DataTable)HttpContext.Current.Session["GetItemCategoryData"];
if ((dt != null))
{
dv = dt.Copy().DefaultView;
dv.RowFilter = "Name like '%" + prefixText + "%' ";
dv.Sort = "Name Asc";
string c = prefixText;
double Num = 0;
bool isNum = double.TryParse(c, out Num);
int indx = 0;
foreach (DataRowView dvr in dv)
{
if (indx <= count)
{
suggestions.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dvr["Name"].ToString().Trim(), dvr["Category_Code"].ToString().Trim()));
indx += 1;
}
}
}
return suggestions.ToArray();
}