AutoCompleteExtender仅在有回发后才有效。页面第一次加载,文本框中的用户类型,它不起作用。但是在有像checkedChanged,buttonClick等的回发之后,&用户类型现在,建议列表显示。它就像...只有在回发后激活扩展器。
ASPX:
<asp:radiobutton id="rbenter" runat="server" text="enter code" groupname="search"
oncheckedchanged="rbenter_change" autopostback="true"/>
<asp:radiobutton id="rbselect" runat="server" text="select code"
groupname="search" oncheckedchanged="rbselect_change" autopostback="true"/>
<asp:TextBox ID="txtSearch" runat="server" OnTextChanged="txtSearch_TextChanged"
onchange="itemSelected();"></asp:TextBox>
<asp:AutoCompleteExtender ID="ace" runat="server" TargetControlId="txtSearch"
MinimumPrefixLength="2" EnableCaching="true" CompletionSetCount="10"
CompletionInterval="0" ServiceMethod="GetCodes" UseContextKey="True"
CompletionListCssClass="autoComplete"
CompletionListItemCssClass="autoCompleteItem"
CompletionListHighlightedItemCssClass="autoCompleteHL"
>
</asp:AutoCompleteExtender>
我找到了罪魁祸首。这是由page_load上的txtSearch.focus()导致的。在页面加载时,txtSearch获得焦点。当我评论这个,工作正常。但我仍然想知道,当它获得焦点时,它如何在回发上工作。我希望即使它有焦点,我也可以在页面上首次加载它。
CS:
protected void Page_Load()
{
if(!IsPostBack)
{
rbenter.checked=true;
rbselect.checked=false;
txtSearch.visible=true;
//txtSearch.focus(); -- works fine when commented
}
}
protected void rbenter_change()
{
txtSearch.visible=true;
txtSearch.focus();
}
protected void rbselect_change()
{
txtSearch.visible=false;
}
答案 0 :(得分:1)
更新您的更新面板,如下所述:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
// Few Other triggers
<%--<asp:AsyncPostBackTrigger ControlID="txtSearch"/>--%>
</Triggers>
<ContentTemplate>
<asp:TextBox ID="txtSearch" runat="server" AutoPostBack="True" OnTextChanged="txtSearch_TextChanged"
onchange="itemSelected(this);" ></asp:TextBox>
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtSearch"
MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="10"
CompletionInterval="0" ServiceMethod="GetCodes" UseContextKey="True"
CompletionListCssClass="autoComplete"
CompletionListItemCssClass="autoCompleteItem"
CompletionListHighlightedItemCssClass="autoCompleteHL">
</asp:AutoCompleteExtender>
</ContentTemplate>
</asp:UpdatePanel>
答案 1 :(得分:1)
如果您从SERVER.TRANSFER
指令登陆到您的网页AUTOCOMPLETE
将在第一次回发之前运行;使用RESPONSE.REDIRECT
代替SERVER.TRASFER
,一切都会好的。