locked
Autocomplete Textbox Using Database Return Value in ASP.NET RRS feed

  • Question

  • User-1497429768 posted

    Hi,

    I use autocompleteExtender to key into a textbox, the value will come from a database table.setting UseContextKey=true,and the ContextKey depend on dropdown control.

    When I click the dropdown first,the value come from a database table is what I need.In the meanwhile,I found the dropdown value is wrong,I select another dropdown value,and enter same keyword into the  textboxand,but the value come from a database still show the privious value,not the correct value what I click the dropdown again.

    For example,firstly,if the dropdown value is A,I enter keyword test into the textbox,the value what come from a database table is A1,but in the same time,I found the dropdown value should be B,I change the dropdown value is B,and I enter keyword test into the textbox again,the value what come from a database table still is A1,not show the correct value B1.

    So,how to fix the code?Thanks.

    Wednesday, April 2, 2014 9:54 PM

Answers

  • User1208776063 posted

    Why don't you add the event in the page markup? I'm assuming on keyup would make a difference.

    TextBox1.Attributes.Add("onnkeyup", "Textbox1_onkeyup();")
    
    function Textbox1_onkeyup() {
       $find('<%=AutoCompleteExtender1.ClientID%>').set_contextKey(document.getElementById("<%=DropDownList1.ClientID %>").value);          
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 3, 2014 7:47 AM

All replies

  • User1208776063 posted

    I found the dropdown value should be B,I change the dropdown value is B,and I enter keyword test into the textbox again,the value what come from a database table still is A1,not show the correct value B1.

    This is my wild guess without taking a look at your code. It seems like you are not refreshing the contextkey when textbox text is changed(use keypress event)

    <script type="text/javascript">
        function refreshContextKey() {
            $find('<%=AutoCompleteExtender1.ClientID%>').set_contextKey(document.getElementById("<%=DropDownList1.ClientID %>").value);
        }
    </script>
    <asp:TextBox ID="TextBox1" runat="server" onkeyup="refreshContextKey();"></asp:TextBox>

    Wednesday, April 2, 2014 10:37 PM
  • User-1497429768 posted

    Hi,dotnetzoom

     Thank you for your help.The following is my code

    function Textbox1_onkeydown() {
       $find('<%=AutoCompleteExtender1.ClientID%>').set_contextKey(document.getElementById("<%=DropDownList1.ClientID %>").value);          
    }

    In codebehind,

    Textbox1.Attributes("onkeydown") = "return Textbox1_onkeydown(this.value);"

    Now,Modify the code to look like your method.But it can't work smart,Maybe you can test ,you will get same result.It's so strange but it's true.

    Thursday, April 3, 2014 2:16 AM
  • User1208776063 posted

    Why don't you add the event in the page markup? I'm assuming on keyup would make a difference.

    TextBox1.Attributes.Add("onnkeyup", "Textbox1_onkeyup();")
    
    function Textbox1_onkeyup() {
       $find('<%=AutoCompleteExtender1.ClientID%>').set_contextKey(document.getElementById("<%=DropDownList1.ClientID %>").value);          
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 3, 2014 7:47 AM
  • User-1497429768 posted

    Hi dotnetzoom:

        I try every method,it still can't work fine.I believe if I can clear the cache of the TextBox1 control,maybe it will be perfect.

       If I select DropDownList1 value,and I key the string A in the Textbox1,the result is what I want. Next,I change DropDownList1 value,and I key the string A in the Textbox1,the result will be wrong.the Autocomplete Textbox effects doesn't appear immediately.When I refresh the form,it will show the right result. It's so strange. anyway,Thank you..

    Thursday, April 17, 2014 5:25 AM