PDA

View Full Version : Lỗi autocomlete?



thuanbk
27-01-2010, 11:14
Mình tạo một trang autocomplete sử dụng ajax chạy rất tốt nhưng khi code các sự kiện cho button.... Khi click vào trang vẫn đứng yên không thay dổi gì cả, đến khi xóa autocomplete thì lại chạy bình thường
Bạn nào biết hay đã từng gặp lỗi này thi support mình với
đây là code của mình



<asp:TextBox ID="txt_thuoc" runat="server" autocomplete="off"></asp:TextBox>
<cc1:ToolkitScriptManager runat="server" ID="ScriptManager1" />
<cc1:AutoCompleteExtender
runat="server"
BehaviorID="AutoCompleteEx"
ID="autoComplete1"
TargetControlID="txt_thuoc"
ServicePath="AutoComplete.asmx"
ServiceMethod="GetCompletionList"
MinimumPrefixLength="1"
CompletionInterval="0"
EnableCaching="true"
CompletionSetCount="10"
CompletionListCssClass="autocomplete_completionListElement"
CompletionListItemCssClass="autocomplete_listItem"
CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
DelimiterCharacters=";, :"
Enabled="True"
UseContextKey="True"
ContextKey="Search-ht_thuoc-ten">
<Animations>
<OnShow>
<Sequence>
<%-- Make the completion list transparent and then show it --%>






<OpacityAction Opacity="0" />
<HideAction Visible="true" />
<%--Cache the original size of the completion list the first time
the animation is played and then set it to zero --%>






<ScriptAction Script="
// Cache the size and setup the initial size
var behavior = $find('AutoCompleteEx');
if (!behavior._height) {
var target = behavior.get_completionList();
behavior._height = target.offsetHeight - 2;
target.style.height = '0px';
}" />
<%-- Expand from 0px to the appropriate size while fading in --%>






<Parallel Duration="0">
<FadeIn />
<Length PropertyKey="height" StartValue="0" EndValueScript="$find('AutoCompleteEx')._height" />
</Parallel>
</Sequence>
</OnShow>
<OnHide>
<%-- Collapse down to 0px and fade out --%>






<Parallel Duration=".4">
<FadeOut />
<Length PropertyKey="height" StartValueScript="$find('AutoCompleteEx')._height" EndValue="0" />
</Parallel>
</OnHide>
</Animations>
</cc1:AutoCompleteExtender>
<script type="text/javascript">
// Work around browser behavior of "auto-submitting" simple forms
var frm = document.getElementById("aspnetForm");
if (frm) {
frm.onsubmit = function() { return false; };
}
</script>
<%-- Prevent enter in textbox from causing the collapsible panel from operating --%>
<input type="submit" style="display:none;" />


Đay là method sử lý


public string[] GetCompletionList(string prefixText, int count, string contextKey)
{
try
{
string[] str = contextKey.Split('-');
string procName = str[0];
string tableName = str[1];
string colummName = str[2];
string str_ketnoi = System.Configuration.ConfigurationManager.AppSetti ngs["NOI_CSDL"];
string str_DBO = System.Configuration.ConfigurationManager.AppSetti ngs["DBO"];
if (count == 0)
{
count = 10;
}
if (prefixText.Equals("xyz"))
{
return new string[0];
}
DataSet ds = DataHelper.ExecuteDataset(str_ketnoi, str_DBO + procName, tableName, colummName, prefixText);
DataTable dt = ds.Tables[0];
count = (dt.Rows.Count < 10) ? dt.Rows.Count : count;
List<string> items = new List<string>(count);
for (int i = 0; i < count; i++)
{
DataRow dr = dt.Rows[i];
items.Add(dr[colummName].ToString());
}
return items.ToArray();
}
catch (Exception)
{
return new string[0];
}
}