locked
AutoCompleteExtender - Fill multiple textboxes RRS feed

  • Question

  • User11355836 posted

    Hey,

    I am using the AutoCompleteExtender and I would like to fill multiple boxes depending on what is returned and not sure the best way of doing so. 

    If possible I would like to do a search on a name, when that name is selected (clicked or Enter pressed) I would like to return the ID of the person from the DB to another method to gather all the information from the Database and pre populate other textboxes, the name slelected would populate the AutoComplete text box.  Is there a way to call another method after a selection has been made on the AutoCompleteExtender?

    Thanks,

    Curtis

    Monday, August 25, 2008 6:22 PM

Answers

  • User583989486 posted

    Hi Kingsley,

    Pls is there anyway to do that. I am quite new to Ajax and javascript. 

    Add an UpdatePanel to your page and move the ListBox , TextBox and its tied AutoCompleteExtender to the UpdatePanel.    When the we select from the AutoCompleteList, we manually force the UpdatePanel to be refreshed.     For example,

    <UpdatePanel UpdateMode="Conditional">

         <TextBox><AutoCompleteExtender>

        <ListBox>

       <Hidden Button> // for example, <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" style="display:none"/>

    </UpdatePanel>

     function AutoCompleteExtender2_ItemSelected(source, eventArgs ){

                   $get("<%=Button1.ClientID%>").click();   // this will force the UpdatePanel to be refreshed.      

                }

    On code behind, we can do something on the Button's click event.  For example,

        protected void Button1_Click(object sender, EventArgs e)
        {

        }

    To me, I would prefer the former one, which is much more effective by avoiding postback.  By the way, AJAX works depend on Javascript.  Therefore, we recommend that you'd better take a look at Javascript Language Sepcification.

    Best regards,

    Jonathan

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 28, 2008 2:57 AM

All replies

  • User583989486 posted

    Hi Curtis,

    If possible I would like to do a search on a name, when that name is selected (clicked or Enter pressed) I would like to return the ID of the person from the DB to another method to gather all the information from the Database

             /// <summary>
            /// Create a serialized JSON object representing a text/value pair that can
            /// be returned by the webservice.
            /// </summary>
            /// <param name="text">Text</param>
            /// <param name="value">Value</param>
            /// <returns>serialized JSON object representing the text/value pair</returns>
            public static string CreateAutoCompleteItem(string text, string value)
            {
                return new JavaScriptSerializer().Serialize(new Pair(text, value));
            }

    Actually,  AutoCompleteExtender allows you return a pair(text,value).   For the sample, please see my reply on this thread. 

    pre populate other textboxes, the name slelected would populate the AutoComplete text box.  Is there a way to call another method after a selection has been made on the AutoCompleteExtender?

    We suggest that you'd better attach a handler to the AutoCompleteExtender and this handler will be triggered when we select an item.  For example,

    <ajaxToolkit:AutoCompleteExtender runat="server" ID="autoComplete1" BehaviorID="myACEBID"
                    TargetControlID="TBSearch" ServicePath="AutoComplete.asmx" ServiceMethod="GetCompletionListsss"
                    MinimumPrefixLength="1" CompletionInterval="1" EnableCaching="true" CompletionSetCount="12"
                    CompletionListElementID="myPanel" OnClientItemSelected="AutoCompleteExtender2_ItemSelected" />

     function AutoCompleteExtender2_ItemSelected(source, eventArgs ){
                  // call another webservice to get more details.              

                }

    How to call WebSerivce, please reference to this document.

    Best regards,

    Jonathan

    Wednesday, August 27, 2008 9:54 PM
  • User-371790594 posted

     Hi Jonathan

    i need some help with ajax Autocomplete extender. i want to put the results when the autocomplete extender is used on a textbox and place it in a listbox instead of geting the dropdown of all the results. 

     

    Pls is there anyway to do that. I am quite new to Ajax and javascript. 

     

    Thanks for the help in advance 

    Kingsley

    Thursday, August 28, 2008 2:17 AM
  • User583989486 posted

    Hi Kingsley,

    Pls is there anyway to do that. I am quite new to Ajax and javascript. 

    Add an UpdatePanel to your page and move the ListBox , TextBox and its tied AutoCompleteExtender to the UpdatePanel.    When the we select from the AutoCompleteList, we manually force the UpdatePanel to be refreshed.     For example,

    <UpdatePanel UpdateMode="Conditional">

         <TextBox><AutoCompleteExtender>

        <ListBox>

       <Hidden Button> // for example, <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" style="display:none"/>

    </UpdatePanel>

     function AutoCompleteExtender2_ItemSelected(source, eventArgs ){

                   $get("<%=Button1.ClientID%>").click();   // this will force the UpdatePanel to be refreshed.      

                }

    On code behind, we can do something on the Button's click event.  For example,

        protected void Button1_Click(object sender, EventArgs e)
        {

        }

    To me, I would prefer the former one, which is much more effective by avoiding postback.  By the way, AJAX works depend on Javascript.  Therefore, we recommend that you'd better take a look at Javascript Language Sepcification.

    Best regards,

    Jonathan

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 28, 2008 2:57 AM
  • User11355836 posted

    it seems as though the .net 3.5 framework that I have doesn't have an OnClientItemSelected.  I am using VS 2008 and Windos Vista, do I need to upgrade the framework from somewhere?

    Tuesday, September 2, 2008 3:14 PM
  • User11355836 posted

    Never mind, I got the update on 3.5.  What is the BehaviorID for and do I need to use the CompletionListElementID?

    Tuesday, September 2, 2008 3:47 PM
  • User583989486 posted
    Hi Curtis, 
    What is the BehaviorID for
    It used to be tricky to get a reference to a behavior from client script, but now you can simply add a "BehaviorID" attribute to your control's property specification and it will be easily accessible on the client via ASP.NET AJAX's Sys.Application.findComponent(id) method or its $find(id) shortcut. (Note: If BehaviorID isn't specified, the behavior's ID on the client will be the same as the extender control's ClientID.) See DynamicPopulate or ResizableControl for examples.

    do I need to use the CompletionListElementID?

    If you want to force the CompletionList showing in a certain container,  you can associate the container with CompletionListElementID.  However, without it, the AutoCompleteExtender still works with its default container.  We suggest that you'd better take a look at this document and its tied video tutorial.

    Best regards,

    Jonathan

     

    Tuesday, September 2, 2008 9:54 PM