Pressing Enter not working for me

4 posts, 0 answers
  1. Steve
    Steve avatar
    84 posts
    Member since:
    Aug 2013

    Posted 03 Dec 2013 Link to this post

    I have a combobox that is filled with a datasource. It filters the dropdown as I type. When I press the enter key, it simply closes the combobox and does nothing. I tried using the onClientKeyPressing event and monitoring on the enter key, but that prevents the combobox from filtering the dropdown entries.

    What I want to happen is to be able to type and the dropdown entries filter. When the I press the enter key, I want to execute some javascript code. I want to be able to execute javascript code when the user either selects an entry from the dropdown or presses the enter key.

    Here is what I have that does not work.
    <telerik:RadComboBox ID="CustomerSearch" runat="server" Width="180" Height="160"
         MarkFirstMatch="true" AllowCustomText="true" CssClass="CustomerSearch" AutoPostBack="false"
         OnClientKeyPressing="HandleKeyPress" EnableVirtualScrolling="true" ShowMoreResultsBox="true"
         EmptyMessage="Enter last, first to search..." BackColor="White" Skin="Forest" />
     
    <asp:SqlDataSource ID="dsCustomer" runat="server"
          SelectCommand="CustomerSearchName" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
     
    <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
                <script type="text/javascript">
                    function searchnav(sender, args) {
                        var iframe = document.getElementById('ctl00_iMainPages');
     
                            if (sender.get_value() != null && sender.get_value() != '') {
                                iframe.src = sender.get_value() + '&T=Client';
                            }                  
                    }
                    function HandleKeyPress(sender, args) {
     
                        if (e.get_domEvent().keyCode == 13) {
                            searchnav(sender, args);
                        }
                    }
                </script>
    </telerik:RadScriptBlock>
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 04 Dec 2013 Link to this post

    Hi Steve,

    Please try the following JavaScript to achieve your scenario which works fine at my end.

    JavaScript:
    <script type="text/javascript">
        function HandleKeyPress(sender, args) {
            if (args.get_domEvent().keyCode == 13) {
                //if the enter key is pressed it will call the searchnav
                searchnav(sender, args);
            }
        }
        function searchnav(sender, args) {
            sender.get_text();
            }
        }
    </script>

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Steve
    Steve avatar
    84 posts
    Member since:
    Aug 2013

    Posted 04 Dec 2013 Link to this post

    The code you offered is pretty much the same as what I am currently doing. The problem is when it is checking the e.get_domEvent().keyCode == 13 in the HandleKeyPress function, the dropdown does not position itself to the first matching item being typed in the combobox. The dropdown does happen, but as I type, it is supposed to highlight the first matching item. This does not happen.

    I comment out the line code inside HandleKeyPress and it does the positioning. If I execute just this:

    function HandleKeyPress(sender, args) {

         if (e.get_domEvent().keyCode == 13) {
            //    searchnav(sender, args);
         }
    }


    It does not work. It will not highlight anything in the dropdown.
  5. Steve
    Steve avatar
    84 posts
    Member since:
    Aug 2013

    Posted 04 Dec 2013 Link to this post

    I found the problem. In the HandleKeyPress function, I was checking e.get_domEvent instead of args.get_domEvent.

    Thanks for your assistance.
Back to Top