Wednesday, June 11, 2008

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" />


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

Digg It! Add to Stumble This