In the AutoCompleteExtender OnClientItemSelected property add the JavaScript method to be called: OnClientItemSelected=”AutoCompletedClientItemSelected”
Within the AutoCompletedClientItemSelected JavaScript method issue a __doPostBack(“AutoCompleteExtender”, sender._element.value); which will induce the postback to the server.
Code Behind Page:
Filter the EventTarget message sent from the JavaScript method in the Page_Load event.
Within the AutoCompletedClientItemSelected JavaScript method issue a __doPostBack(“AutoCompleteExtender”, sender._element.value); which will induce the postback to the server.
01 | < script language = "javascript" type = "text/javascript" > |
02 | // postBack handler for AJAX AutoComplete Extender - onClientItemSelected |
03 | function AutoCompletedClientItemSelected(sender, e) { |
04 | __doPostBack("AutoCompleteExtender", sender._element.value); |
05 | } |
06 |
07 | </ script > |
08 |
09 | < div id = "find" > |
10 | < div id = "findbox" > |
11 | < span class = "label" >JHA Name</ span > |
12 | < asp:TextBox ID = "tbJHAName" CssClass = "namebox" runat = "server" AutoComplete = "Off" |
13 | Width = "550px" Style = "margin-top: 0px" ></ asp:TextBox > |
14 | </ div > |
15 | < asp:AutoCompleteExtender ID = "tbJHAName_AutoCompleteExtender" runat = "server" Enabled = "true" |
16 | ServicePath = "" ServiceMethod = "GetJHANames" TargetControlID = "tbJHAName" MinimumPrefixLength = "3" |
17 | UseContextKey = "True" OnClientItemSelected = "AutoCompletedClientItemSelected" > |
18 | </ asp:AutoCompleteExtender > |
19 | < a id = "linkAdvancedSearch" class = "advancedlink" href = "Javascript:void(0)" onclick = "ShowAdvanced(this);" > |
20 | Advanced Search</ a > |
21 | </ div > |
Filter the EventTarget message sent from the JavaScript method in the Page_Load event.
01 | protected void Page_Load( object sender, EventArgs e) |
02 | { |
03 | if (IsPostBack) |
04 | { |
05 | // postBack handler for AJAX AutoComplete Extender - JavaScript call: AutoCompletedClientItemSelected |
06 | if (Request.Form[ "__EVENTTARGET" ] != null && |
07 | Request.Form[ "__EVENTTARGET" ] == "AutoCompleteExtender" && |
08 | Request.Form[ "__EVENTARGUMENT" ] != null ) |
09 | { |
10 | // Emulate button click search |
11 | btnSearch_Click( null , null ); |
12 |
13 | } |
14 | } |
No comments:
Post a Comment