PostBack the form when a value is selected from the results returned by autocomplete extender

Some times we would like to do a post back when we select a value from the results returned by the Autocomplete extender. To do this you can leverage one of the client side properties that the AutoComplete Extender exposes. The property is OnClientItemSelected which takes a javascript method name as value.


<asp:UpdatePanel runat="server" id="UpdatePanel1" >

<asp:TextBox ID="txtOrderNumber" runat="server"
AutoCompleteType="Disabled" MaxLength="5"></asp:TextBox>

<ajaxToolkit:AutoCompleteExtender ID="OrderNumberAutoCompleteExtender"
runat="server" CompletionInterval="100" CompletionSetCount="20"
EnableCaching="true" MinimumPrefixLength="2"
ServiceMethod="GetOrderList" ServicePath="~/ASPX/Common/AutoComplete.asmx"
TargetControlID="txtOrderNumber" OnClientItemSelected="OrderNumberChanged" />

</asp:UpdatePanel>

<Script type="text/javascript">
function OrderNumberChanged( source, eventArgs )
{
__doPostBack('<%=UpdatePanel1.ClientID%>', ''); //do a postback
}
</Script>

 

 

發佈了14 篇原創文章 · 獲贊 3 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章