Radmenu item not fire when press Enter in RadTextBox

2 posts, 0 answers
  1. Howard
    Howard avatar
    6 posts
    Member since:
    Nov 2012

    Posted 27 Dec 2013 Link to this post

    I am using javascript to trigger the radmenu item. But when I enter value in textbox and press "Enter", the page is postback without trigger the radmenu item. my code as below:

    Javascript:
    function CkKeyPress(e) {
          var evt = (e) ? e : window.event;
          var key = (evt.keyCode) ? evt.keyCode : evt.which;
          if (key == 13) {
               var dealer = document.getElementById('<%=textbox1.ClientID%>').value;
                            var menu = $find("<%= radMenu1.ClientID%>");
                            var templateButton = menu.findItemByText("Next");
                            templateButton.click();
                }
    }

    Asp.net
    <telerik:RadMenu ID="radMenu1" runat="server" Style="top: 0px; left: 0px">
         <Items>
                <telerik:RadMenuItem runat="server" Text="Next" Value="Next">
                 </telerik:RadMenuItem>
          </Items>
    </telerik:RadMenu>

    <telerik:RadNumericTextBox ID="txtAmount" runat="server" Culture="en-US" DbValueFactor="1" LabelWidth="64px" Width="160px" AutoCompleteType="Disabled" onkeypress="CkKeyPress(event)">
    </telerik:RadNumericTextBox>

    Vb.net
    Private Sub radMenu1_ItemClick(sender As Object, e As RadMenuEventArgs) Handles radMenu1.ItemClick
           Response.Redirect("sample.aspx")
    End Sub

    I am using vs 2012 and telerik 2013
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 27 Dec 2013 Link to this post

    Hi Howard,

    Please try to ajaxify the RadMenu to avoid the postback and attach the RadMenu OnItemClick event in ASPX also. Please have a look into the following code snippet.

    ASPX:
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="radMenu1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="radMenu1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadMenu ID="radMenu1" runat="server" OnItemClick="radMenu1_ItemClick" Style="top: 0px;
        left: 0px">
        <Items>
            <telerik:RadMenuItem runat="server" Text="Next" Value="Next">
            </telerik:RadMenuItem>
        </Items>
    </telerik:RadMenu>
    <telerik:RadNumericTextBox ID="txtAmount" runat="server" Culture="en-US" DbValueFactor="1"
        LabelWidth="64px" Width="160px" AutoCompleteType="Disabled" onkeypress="CkKeyPress(event)">
    </telerik:RadNumericTextBox>

    Thanks,
    Princy.
Back to Top