我有一个AJAX AutoCompleteExtender,在GridView,如下所示:集ContextKey为AutoCompleteExtender里面的GridView
<asp:GridView
ID="GV1"
runat="server"
AllowPaging="True"
OnPageIndexChanging="GV1_OnPageIndexChanging"
OnRowCommand="GV1_RowCommand">
...
<asp:TextBox
ID="txt1"
runat="server"
onkeyup = "SetContextKey()">
</asp:TextBox>
<cc1:AutoCompleteExtender
ID="AutoCompleteExtender1"
runat="server"
TargetControlID="txt1"
ServiceMethod="GetACEList"
ServicePath="AutoComplete.asmx"
UseContextKey = "true"
MinimumPrefixLength="1"
EnableCaching="true"
CompletionSetCount="1"
CompletionInterval="100"
CompletionListCssClass="autocomplete_completionListElement"
CompletionListItemCssClass="autocomplete_listItem"
CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem">
</cc1:AutoCompleteExtender>
...
</asp:GridView>
当试图设置上下文键,我无法访问在该AutoCompleteExtender
客户端以及服务器端。
在客户端,我想:
function SetContextKey() {
$find('AutoCompleteExtender1').set_contextKey($get("<%=ddlCountry.ClientID%>").value);
}
但JavaScript是无法找到 'AutoCompleteExtender1' 对象。 我意识到这是因为生成的HTML中有很多'AutoCompleteExtender1'对象,每个对象都有唯一的ID。
然后我发现this article,我尝试设置在服务器端的背景下键:
protected void ddlCountry_OnSelectedIndexChanged(object sender, EventArgs e) {
AutoCompleteExtender1.ContextKey = ddlCountry.SelectedValue;
}
但代码编译失败,出现错误: The name 'AutoCompleteExtender1' does not exist in the current context
问题:
如何访问选定索引c上的AutoCompleteExtender1
对象下拉下拉以便我可以设置上下文键?
添加一些描述以使答案更好。 – 2016-06-27 19:07:26